Caesar Cipher - Program to encrypt input

Caesar Cipher - Program to encrypt input

Accept this challenge and paste the code in comment section


Caesar Cipher - Program to encrypt input
Img. Source - geeksforgeeks.com
The Ceasar Cipher is a type of message encrypting technique. In Ceasar Cipher each letter in the text is shifted to a certain number of places down the alphabet. Like if you enter B with the shift of 1 output should be C. If you enter hello output should be ifmmp.

Example of Ceasar Cipher Code

Input : "I love programming."

Output : " J mpwf qsphsbnnjoh."

1 Response to "Caesar Cipher - Program to encrypt input"

  1. # python code

    def encrypt(text,s):

    result = ""

    for i in range(len(text)):

    char = text[i]

    if (char.isupper()):

    result += chr((ord(char) + s-65) % 26 + 65)




    else:

    result += chr((ord(char) + s - 97) % 26 + 97)



    return result


    #check the above function

    text = "ATTACKATONCE"

    s = 4

    print "Text : " + text

    print "Shift : " + str(s)

    print "Cipher: " + encrypt(text,s)

    ReplyDelete

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel