Caesar Cipher

    0

    0

    Mahendra Kumar

    intermediatecryptographyciphers

    python program implementing Caesar cypher

    def encrypt(text,s):
    result = ""
       # transverse the plain text
       for i in range(len(text)):
          char = text[i]
          # Encrypt uppercase characters in plain text
          if (char.isupper()):
             result += chr((ord(char) + s-65) % 26 + 65)
          # Encrypt lowercase characters in plain text
          else:
             result += chr((ord(char) + s - 97) % 26 + 97)
          return result
    #check the above function
    text = "CEASER CIPHER DEMO"
    s = 4
    print "Plain Text : " + text
    print "Shift pattern : " + str(s)
    print "Cipher: " + encrypt(text,s)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.