Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cesar Cipher
#6
I learned this whilst working for MI5! (Top secret, don't tell anyone!)

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
from string import ascii_lowercase, ascii_uppercase, digits, punctuation, whitespace
 
alpha = ascii_uppercase + ascii_lowercase + digits + punctuation
len(alpha) # 94
 
# Thank you Franz Schubert!
text = '''Ave Maria
Gratia plena
Maria, gratia plena
Maria, gratia plena
Ave, ave dominus
Dominus tecum
Benedicta tu in mulieribus
Et benedictus
Et benedictus fructus ventris
Ventris tuae, Jesus.
Ave Maria'''
 
def cyberSecurity(text):
    text_list = [t for t in text]
    for i in range(len(text_list)):
        if text_list[i] in alpha:
            index = alpha.index(text_list[i])
            # go back to the beginning if index > len(alpha) - 4
            if index > len(alpha) - 5:
                index = 4 - (len(alpha) - index )
                text_list[i] = alpha[index]
            else:
                text_list[i] = alpha[index+4]
    coded = ''.join(text_list)
    return coded
 
print(cyberSecurity(text))
Unbreakable code, but hard to sing!

Output:
Ezi Qevme Kvexme tpire Qevme: kvexme tpire Qevme: kvexme tpire Ezi: ezi hsqmryw Hsqmryw xigyq Firihmgxe xy mr qypmivmfyw Ix firihmgxyw Ix firihmgxyw jvygxyw zirxvmw Zirxvmw xyei: Niwyw< Ezi Qevme
Reply


Messages In This Thread
Cesar Cipher - by ForsakenDusk - Mar-31-2024, 09:40 AM
RE: Cesar Cipher - by snippsat - Mar-31-2024, 11:59 AM
RE: Cesar Cipher - by ForsakenDusk - Mar-31-2024, 04:45 PM
RE: Cesar Cipher - by deanhystad - Mar-31-2024, 10:31 PM
RE: Cesar Cipher - by ForsakenDusk - Apr-07-2024, 01:26 PM
RE: Cesar Cipher - by Pedroski55 - Apr-07-2024, 04:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Rsa Cipher Paragoon2 3 1,467 Nov-27-2023, 12:30 PM
Last Post: snippsat
  RSA Cipher with blocks Paragoon2 0 1,126 Nov-26-2023, 04:35 PM
Last Post: Paragoon2
  Transposition Cipher Issues beginner_geek07 0 1,683 Apr-08-2022, 07:44 PM
Last Post: beginner_geek07
  Caesar Cipher Help pbrowne 2 3,059 Jun-30-2021, 02:36 PM
Last Post: deanhystad
  Coding caesar's cipher drewbty 3 4,008 May-16-2020, 10:05 AM
Last Post: DPaul
  cipher decryption tool nightfox82 0 1,835 Mar-25-2020, 06:36 AM
Last Post: nightfox82
  Problem with caesar cipher lucaron 2 3,685 Feb-05-2018, 05:17 PM
Last Post: lucaron
  Decrypt Caesar Cipher WantToImprove 22 22,458 Jan-30-2018, 08:43 AM
Last Post: WantToImprove
  Simple Caesar Cipher Help as1221 6 6,684 Jun-15-2017, 10:22 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020