caesar cipher in python

def caesar_encrypt():
    word = input('Enter the plain text: ')
    c = ''
    for i in word:
        if (i == ' '):
            c += ' '
        else:
            c += (chr(ord(i) + 3))
    return c

def caesar_decrypt():
    word = input('Enter the cipher text: ')
    c = ''
    for i in word:
        if (i == ' '):
            c += ' '
        else:
            c += (chr(ord(i) - 3))
    return c
  
plain = 'hello'
cipher = caesar_encrypt(plain)
decipher = caesar_decrypt(cipher)
  

3.8
10
Tinybatte 90 points

                                    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)

3.8 (10 Votes)
0
4
8

                                    plaintext = input("Please enter your plaintext: ")
shift = input("Please enter your key: ")
alphabet = "abcdefghijklmnopqrstuvwxyz"
ciphertext = ""

# shift value can only be an integer
while isinstance(int(shift), int) == False:
  # asking the user to reenter the shift value
  shift = input("Please enter your key (integers only!): ")

shift = int(shift)
  
new_ind = 0 # this value will be changed later
for i in plaintext:
  if i.lower() in alphabet:
    new_ind = alphabet.index(i) + shift
    ciphertext += alphabet[new_ind % 26]
  else:
    ciphertext += i    
print("The ciphertext is: " + ciphertext)

4 (8 Votes)
0
0
4
Bandrade 140 points

                                    def ascii_caesar_shift(message, distance):
    encrypted = ""
    for char in message:
        value = ord(char) + distance
        encrypted += chr(value % 128) #128 for ASCII
    return encrypted

0
0
3.9
10
Supine man 90 points

                                    def cc_encrypt(msg: str,key: int) -> str:
    encrypted_msg = ''

    try:
        for char in msg:
            encrypted_msg += str(chr(ord(char)+int(key)))
    except:
        print(Exception)
        pass
    
    return encrypted_msg

def cc_decrypt(msg: str,key: int) -> str:
    decrypted_msg = ''

    try:
        for char in msg:
            decrypted_msg += chr(ord(char)-int(key))
    except:
        print(Exception)
        pass

    return decrypted_msg

  
message = 'Hello World!'
key = 9
print(f'Caesar Cipher:\nEncrypted: {cc_encrypt(message,key)}\nDecrypted: {cc_decrypt(cc_encrypt(message,key),key)}')

3.9 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
Algorithm of Caesar Cipher python Index Caesar Cipher in Python Caesar Cipher solution in python caesar cipher in python3 implementing caesar cipher in python writing a caesar cipher in python python code for ceaser cipher decryption python code to decrypt caesar cipher Python code for ceaser cipher Python: plaintext caesar cipher how to write a caesar cipher python python caesar caesar's cipher phrases to decode python Write a Python Program to implement the Caesar cipher technique caesar code put python Ceasar Ciphers in python Ceasar Ciphers python code python find caesar cipher shift python code to determine if a string is a caesar cipher caesar cipher python only characters ceaser cipher program in python caesar cipher python class python caesar cipher class Caesar Cipher decode Python python caesar cipher module caesar decipher python python code that deciphers caesar with key how to do caesar cipher in python how to create a caesar cipher in python caesar cipher python input Simple Caesar Cipher Python ascii caesar cipher python mod Caesar Cipher in Python ascii Caesar cipher Python encrypt function for letter in cipher ceaser python function for encryption in python ceaser = function for encryption in python ceaser python decrypt caesar cipher caesar cipher python ascii keyword ascii julius caesar python encryption with keyword ascii julius caesar python encryption ceacer cipher python the caesar cipher python python automatic caesar cipher decrypt Encryption of message with caesar cipher algorithm using python caesar cipher decryption python code caesar cipher encryption python code how to make a caesar cipher in python decrypt simple ceaser cipher python decipher caesar cipher python caesar cipher in python 3.7 decryption of caesar cipher in python Caesar Cipher Function in Python * easy caesar cipher in python how to encrypt a string using ceaser cypher in python caesar cipher encryption program in python caeser cipher using python ceaser cipher in python how to implement a caesar cypher in python how to implement a ceaser cypher in python encrypt the number using caesar cipher in python ceaser cipher python code caesar cipher python geeks for geeks cracking caesar cipher with python python caesar cipher decoder encrypted message caesar cipher python cesar cipher ++ code python cesar cipher code python cipher code python decryption in caesar cipher in python caesar cipher python decrypt python caesar cipher 26 ceaser cypher python caesar cipher pyt python caesar cipher decrypt function python caesar cipher rules ceaser cipher method in python decrypt caesar cipher python implement caesar cipher in python python crack caesar cipher cipher caesar python caesars cipher python write a program to implement caesar cipher in python caesar cipher pyton caesar python caesar_cipher python cesar-cipher encryption python result += chr((ord(char) + s - 97) % 26 + 97) python caesar cipher encrypt caesarCipher Algorithm shaifted enceiption python python library for caesar cipher encryption and decryption shift caesar cipher python caesar cypher in place python caesar cypher pyhton python caesar encryption python caesar code python cesar cipher caesar cipher solution python caesar cipher python encrypt caesar python script python ceaser cyphe python ceaser cypher by 13 Explain Caesar cipher and Write a python program to implement Caesar cipher cipher in python Algorithm of Caesar python Algorithm of Caesar Cipher python 3 Python - Caesar Ciphe caesar cipher implementation in python caesar decoder python caesar cipher python simple code python ascii cipher Seasar Cypher python python program for additive cipher creating a caesar cipher in python caeser cypher python caeser cypher python script code for decryption of caesar cipher python cipher wheel encryption pytohn caesar cipher example python Convert the plain text ATTACK into cipher text with the key value 4 by using Caesar cipher. * pseudocode caesar cipher caesar's encrption python' caesar cipher encryption code in python caesar cypher python program caesar cipher ceaser chiper python algorithm to caesarCipherText ROT CIPHER python python caesar solver caesar code python simple rotation cypher python a rotation cypher with python caesar cipher encryption and decryption python caesar cipher python ceaser cypeher Create and encrypter in python based on the ceaser cipher python make a cipher python cipher code implementation of caeser cipher in python python how many ciphers in a str rotation cipher python caesar cipher decrypt python python how to create ciphertext python caesar shift code cifer ceasar python python modified caesar cipher cryptography projects in python using caesar chipher caesar cipher python 3 ceizer cipher python cypher method python how to caesar cipher in python caesar cipher python program python caesar cipher shift python caesar cipher decrypt caeser cipher decode python caesar cipher encryption python caeasr cipher python Caesar cipther python 3 code Caesar Cipher encipher in python 3 Caeser Cipher python 3 code python Cipher make a cipher with python caesar cypher in python python fastest way decrypt reverse alphabet julies caesar encryption in python ADS cipher python code using cipher in python decipher a string by shifting in python Caesar cipher pyhton python encode caesar cipher caesar cipher in python socket programming ceaser cipher python program cipher and decipher python code how to convert plain text to cipher text in python program how to break a cipher with a encode function python Decode caesar cipher python caesar cipher decrypt python code code shift cipher python caesar cipher rotation 13code in python from user python library find caesar cipher key python caesar cipher caesar shift encoder python ceasar cipher python python ciphers ciphers in python caesar shift character python caesar encryption python caesar cipher python code break a simple cipher in python Write Python program to implement Caesar’s Cipher. Take user input to get plain text and key. Write Python program to implement Caesar’s Cipher caesar cypher decryption python caesar cipher in python code caesar cipher phyton ceaser code python caesar ciher python ceaser shift python module ceaser shift python caesar cipher using python python caesar cipher code caesar cipher function python simple cypher python Cryptography with Python - Caesar Cipher shift encryption in python how to caesar shift in python how to only cipher letters python caesar cipher python ascii shift decrypt caesar cipher python ascii shift how to use caesar cipher in python cesar cipher python caesar cryptography python with key number caesar cryptography python letter shidt decoder python Write a function which takes a text and encrypts it with a Caesar cipher. python caesar cipher with python implementation of caesar cipher in python simple python rotation cipher programs easy python rotation cipher programs caesar cipher utf 8 python cesar cypher wheel python python program to encrypt a non string cycleshift python program to encrypt a string cycleshift how to create a function that that takes in a plain text phrase and a numeric shift python python cipher encoder caesar cipher algorithm python caesar cypher code in python caesar cipher code in python how to implement caesar cipher in python caesar cipher algorithm in python program in python for the encryption and decryption of ceaser ciper find the time taken by caesar cipher in python how to calculate the time required for the ceaser cypher encyption using python program in python for the encryption and decryption of ceaser ciper and time taked to perform the both operation caesar cipher encryption and decryption program in python casar cipher python geeks for geeks caesar cipher python Caesar Cipher python with numbers Caesar Cipher letters and numbers python cipher python implement caesar cipher encryption-decryption in python how to write a basic caesar cipher in python cipher text python different ways to do a rotation cipher in python shift cypher code python caesar cipher encryption and decryption implementation python caesar cipher python into numbers make ciphers in python or C#? cypher in python caesar cipher decryption python caesar cipher program in python caesar shift python caesar cypher python cipher program in python cipher text with key python coding the caesar cipher in python python ascii caesar cipher caeaser ciper python ceaser cipher python caesar cipher decryption program in python python decrypt shifted alphabet python ceaser cipher function Write a Python program that ask the user to input a line of plaintext and the distance value and outputs an encrypted text using a Caesar cipher, with the ASCII values range from 0 through 127. caesar cipher decryption code in python how to encrypt a message using caesar cipher table in python how to encrypt a message using caesar cipher in python ceaser cipher decryption python python cesar method append caesarCipher python how to make a caesar cipher in python caesar in python caesar cipher python caesar cipher in python python ceasar cipher python caesar cipher
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source