@@ -16,7 +16,7 @@ func generatePrimes(limit int)int{
16
16
primes := prime (limit )
17
17
var choice []int
18
18
choice = append (choice , 1 ,7 ,11 ,13 ,17 ,19 ,23 ,29 )
19
- for {
19
+ for {
20
20
k := rand .Intn (int (limit / 30 ))
21
21
i := choice [rand .Intn (len (choice ))]
22
22
c := 30 * k + i
@@ -137,36 +137,38 @@ func toRune(slice []int)string{
137
137
}
138
138
return str
139
139
}
140
-
140
+
141
141
142
142
func main (){
143
143
rand .Seed (time .Now ().UTC ().UnixNano ())
144
- bits := 15
145
-
144
+ bits := 17
145
+
146
146
p := generatePrimes (1 << bits )
147
147
q := generatePrimes (1 << bits )
148
148
for p == q {
149
149
q = generatePrimes (1 << bits )
150
- }
151
-
150
+ }
151
+
152
152
n := p * q
153
-
153
+
154
154
delta := lcm (p - 1 ,q - 1 )
155
-
155
+
156
156
e := generatePrimes (delta )
157
157
d := modularMultiplicativeInverse (e ,delta )
158
158
159
159
fmt .Printf ("%v \n %v \n %v \n %v\n " ,p ,q ,e ,d )
160
-
160
+
161
161
162
162
str := "I think RSA is really great"
163
163
message := []rune (str )
164
164
asciiSlice := toASCII (message )
165
165
166
- fmt .Printf ("asciiSlice :%v \n " ,asciiSlice )
166
+ fmt .Printf ("asciiSlice : %v \n " ,asciiSlice )
167
167
encrypted := encryptRSA (asciiSlice ,e ,n )
168
- fmt .Printf ("encrypted :%v \n " ,encrypted )
168
+ fmt .Printf ("encrypted : %v \n " ,encrypted )
169
169
decrypted := decryptRSA (encrypted ,d ,n )
170
170
fmt .Printf ("decrypted : %v \n " ,decrypted )
171
171
fmt .Printf ("cleartext : %v \n " ,toRune (decrypted ))
172
+ //switched to atom
173
+
172
174
}
0 commit comments