-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAffinecipher.py
More file actions
35 lines (33 loc) · 1.19 KB
/
Affinecipher.py
File metadata and controls
35 lines (33 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
values_of_a = [3,5,7,9,11,15,17,19,21,25]
a = values_of_a[random.randint(0,9)]
b = random.randint(1,20)
alphabet = "abcdefghijklmnopqrstuvwxyz"
def make_affine_cipher(something):
final_str = ""
something = something.lower()
for letter in something:
if letter not in alphabet:
final_str = final_str + letter
else:
og_number = alphabet.find(letter)
cipher_letter = (og_number*a)+b
final_str = final_str + alphabet[cipher_letter%26]
# picks whether to encode or decode and returns the key
x = random.randint(1,3)
if x<2:
print ("Decode: " + final_str)
x = random.randint(0,3)
# either prints first 4 letters or prints a and b
if x<2:
print (final_str + " The first four letters of the word are: " + something[:5])
return [final_str + " The first four letters of the word are: " + something[:5], something]
else:
print("a:"+str(a))
print("b:"+str(b))
return [final_str, something]
else:
print("Encode: " + something)
print ("a:"+str(a))
print ("b:" +str(b))
return [something, final_str]