This commit is contained in:
Maxime Vorwerk
2024-07-07 13:17:27 +02:00
parent 34efed2553
commit 2715eafddf
2 changed files with 27 additions and 0 deletions

1
vigenere/cipher.txt Executable file
View File

@@ -0,0 +1 @@
rgnoDVD{O0NU_WQ3_G1G3O3T3_A1AH3S_cc82272b}

26
vigenere/sol.py Executable file
View File

@@ -0,0 +1,26 @@
#!/home/maxime/.pyvenv/bin/python3
key = "CYLAB"
with open("cipher.txt", 'r') as f:
cipher = f.read()
plaintext = ""
i = 0
for char in cipher:
char = ord(char)
a = ord('a')
z = ord('z')
A = ord('A')
Z = ord('Z')
keychar = ord(key[i%len(key)]) - A
if a <= char and char <= z:
plaintext += chr((char - a - keychar)%26 + a)
i += 1
elif A <= char and char <= Z:
plaintext += chr((char - A - keychar)%26 + A)
i += 1
else:
plaintext += chr(char)
print(plaintext)