Computer Science, asked by hlo83, 8 months ago

Write a program that encrypt a message by adding a key value to every character. (Caesar

Cipher) hint if key = 3, then add 3 to every characte​

Answers

Answered by akshitasingh19
4

Explanation:

The Caesar Cipher technique is one of the earliest and simplest method of encryption technique. It’s simply a type of substitution cipher, i.e., each letter of a given text is replaced by a letter some fixed number of positions down the alphabet. For example with a shift of 1, A would be replaced by B, B would become C, and so on. The method is apparently named after Julius Caesar, who apparently used it to communicate with his officials.

Thus to cipher a given text we need an integer value, known as shift which indicates the number of position each letter of the text has been moved down.

The encryption can be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,…, Z = 25. Encryption of a letter by a shift n can be described mathematically as.

E_n(x)=(x+n)mod\ 26

(Encryption Phase with shift n)

D_n(x)=(x-n)mod\ 26

(Decryption Phase with shift n)

Caesar Cipher 3

Answered by nancychaterjeestar29
0

Answer:

def caesar_encryption(realText, step):

outtext = []

cryptext = []

Uppercase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

Lowercase = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for eachletter in realtext:

 if eachletter in uppercase:

  index = Uppercase.index(eachLetter)

  crypting = (index + step) % 26

  cryptText.append(crypting)

  newletter = Uppercase[crypting]

  outText.append(newletter)

 else if eachletter in lowercase:

  index = Lowercase.index(eachletter)

  crypting = (index + step) % 26

  cryptText.append(crypting)

  newLetter = Lowercase[crypting]

  outText.append(newletter)

return outText

code = caesar_encryption('abc', 2)

print()

print(code)

print()

#SPJ2

Similar questions