Skip to content

Commit f86861f

Browse files
committed
Update RSAcipher.go
1 parent c462d05 commit f86861f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

ciphers/RSAcipher.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func generatePrimes(limit int)int{
1616
primes:= prime(limit)
1717
var choice []int
1818
choice = append(choice, 1,7,11,13,17,19,23,29)
19-
for{
19+
for{
2020
k:=rand.Intn(int(limit/30))
2121
i:=choice[rand.Intn(len(choice))]
2222
c:=30*k+i
@@ -137,36 +137,38 @@ func toRune(slice []int)string{
137137
}
138138
return str
139139
}
140-
140+
141141

142142
func main(){
143143
rand.Seed(time.Now().UTC().UnixNano())
144-
bits:=15
145-
144+
bits:=17
145+
146146
p:= generatePrimes(1<<bits)
147147
q:= generatePrimes(1<<bits)
148148
for p==q{
149149
q = generatePrimes(1<<bits)
150-
}
151-
150+
}
151+
152152
n:= p*q
153-
153+
154154
delta:=lcm(p-1,q-1)
155-
155+
156156
e:=generatePrimes(delta)
157157
d:=modularMultiplicativeInverse(e,delta)
158158

159159
fmt.Printf("%v \n%v \n%v \n%v\n",p,q,e,d)
160-
160+
161161

162162
str:="I think RSA is really great"
163163
message := []rune(str)
164164
asciiSlice :=toASCII(message)
165165

166-
fmt.Printf("asciiSlice :%v \n",asciiSlice)
166+
fmt.Printf("asciiSlice : %v \n",asciiSlice)
167167
encrypted := encryptRSA(asciiSlice,e,n)
168-
fmt.Printf("encrypted :%v \n",encrypted)
168+
fmt.Printf("encrypted : %v \n",encrypted)
169169
decrypted := decryptRSA(encrypted,d,n)
170170
fmt.Printf("decrypted : %v \n",decrypted)
171171
fmt.Printf("cleartext : %v \n",toRune(decrypted))
172+
//switched to atom
173+
172174
}

0 commit comments

Comments
 (0)