Skip to content

Instantly share code, notes, and snippets.

@umutbasal
Last active May 22, 2024 15:59
Show Gist options
  • Save umutbasal/2747b796ef72603e8fdbd7a1bbf03182 to your computer and use it in GitHub Desktop.
Save umutbasal/2747b796ef72603e8fdbd7a1bbf03182 to your computer and use it in GitHub Desktop.
table_alphabet = "AZBYCVÇÜDUETFŞGSĞRHPIÖİOJNKML"
alphabet = "ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ"
def vinegere_table(alphabet):
table = []
for i in range(len(alphabet)):
table.append(alphabet[-i:] + alphabet[:-i])
return table
table = vinegere_table(table_alphabet)
print("Table:")
for row in table:
print(row)
ciphertext = (
"ÖDOPÇEARREJNSĞKTHJÇIUFIN"
"PŞIUNJEPVÖGÖMUUSPJZÖYCÇYNRĞJNTHUSÜIJFFNĞÖAOÖSAİLEKHUI"
"ÜNCUPPBSÖNTLSHÇÖÖRÜİDDBMLAYAYLTIOÖRND"
"TPRBJUEDYĞHELTAÖFĞRBEJTBUDPZIJVZVİOÜPCŞOSNNHMŞTFJİUACOOISESKSUMÇÜ"
"LBZOBMÇFKZVÇÇZCÖOĞSİCSTLÜ"
)
ciphertext_joined = "".join(ciphertext.split())
print(f"Ciphertext: {ciphertext_joined}")
key = "" # decryption of "MÇIRY IINEE TNHHR VAEND ATRAE"
print(f"Key: {key}")
def pad_key(key, length):
while len(key) < length:
key += key
return key[:length]
key = pad_key(key, len(ciphertext_joined))
print(f"Key: {key}")
def decrypt(ciphertext, key, table):
decrypted = ""
x = 0
for k in key:
key_index = alphabet.index(k)
c_index = alphabet.index(ciphertext[x])
decrypted += table[c_index][key_index]
x+=1
return decrypted
print(f"Decrypted: {decrypt(ciphertext_joined, key, table)}")
#Output
#KÜÇÜKHANIMLARKÜÇÜKBEYLERSİZLERHEPİNİZGELECEĞİNBİRGÜLÜYILDIZIVEİKBALIŞIĞISINIZMEMLEKETİASILIŞIĞABOĞACAKOLANSİZSİNİZKENDİNİZİNNEKAKTRÖNEMLİDEĞERLİOLDUĞUNUZUDÜŞÜNEREKONAGÖREÇALIŞINIZSİZLERDENÇOKŞEYBEKLİYORUZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment