Hola usuario de nuestra página, descubrimos la respuesta a lo que buscabas, continúa leyendo y la hallarás más abajo.
Ejemplo 1: descifrado automático de cifrado césar de Python
x =input()
NUM_LETTERS =26defSpyCoder(S, N):
y =""for i in S:if(i.isupper()):
x =ord(i)
x += N
if x >ord('Z'):
x -= NUM_LETTERS
elif x <ord('A'):
x += NUM_LETTERS
y +=chr(x)else:
y +=" "return y
defGoodnessFinder(S):
y =0for i in S:if i.isupper():
x =ord(i)
x -=ord('A')
y += letterGoodness[x]else:
y +=1return y
defGoodnessComparer(S):
goodnesstocompare = GoodnessFinder(S)
goodness =0
v =''
best_v = S
for i inrange(0,26):
v = SpyCoder(S, i)
goodness = GoodnessFinder(v)if goodness > goodnesstocompare:
best_v = v
goodnesstocompare = goodness
return best_v
print(GoodnessComparer(x))
Ejemplo 2: cifrado césar de python
defcaesar_encrypt():
word =input('Enter the plain text: ')
c =''for i in word:if(i ==' '):
c +=' 'else:
c +=(chr(ord(i)+3))return c
defcaesar_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)
Ejemplo 3: cifrado césar de python
plaintext =input("Please enter your plaintext: ")
shift =input("Please enter your key: ")
alphabet ="abcdefghijklmnopqrstuvwxyz"
ciphertext =""# shift value can only be an integerwhileisinstance(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 laterfor 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)
Ejemplo 4: pitón cifrado césar
defcc_encrypt(msg:str,key:int)->str:
encrypted_msg =''try:for char in msg:
encrypted_msg +=str(chr(ord(char)+int(key)))except:print(Exception)passreturn encrypted_msg
defcc_decrypt(msg:str,key:int)->str:
decrypted_msg =''try:for char in msg:
decrypted_msg +=chr(ord(char)-int(key))except:print(Exception)passreturn decrypted_msg
message ='Hello World!'
key =9print(f'Caesar Cipher:nEncrypted: cc_encrypt(message,key)nDecrypted: cc_decrypt(cc_encrypt(message,key),key)')
Ejemplo 5: cifrado césar en python
defencrypt(text,s):
result =""# transverse the plain textfor i inrange(len(text)):
char = text[i]# Encrypt uppercase characters in plain textif(char.isupper()):
result +=chr((ord(char)+ s-65)%26+65)# Encrypt lowercase characters in plain textelse:
result +=chr((ord(char)+ s -97)%26+97)return result
#check the above function
text ="CEASER CIPHER DEMO"
s =4print"Plain Text : "+ text
print"Shift pattern : "+str(s)print"Cipher: "+ encrypt(text,s)
Al final de la página puedes encontrar los comentarios de otros creadores, tú igualmente tienes la libertad de insertar el tuyo si lo deseas.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)