Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
An attempt at making an encrypting algo in Python.
''' Example or "What am I aiming for?" abcd ----(encrypting) ---> cded (This pattern kind of recognisable here, isn't it?) dcba ----(encrypting) ---> feda (Don't think this is much similar to the original string. Is it?) ACEGI ----(encrypting) ---> EGIKI (Not at all similar to the original string. That's a good think.) James ----(encrypting) ---> xy}s James Collins ----(encrypting) ---> xy}ęfulrsxs Seems like we lost a bit of information, but it's actually not the case. The character is their but it's just not rendered. I have checked it using the 'len()' function on the encrypted version of the string. Also, good on you for noticing that missing character. There's 1 problem in this program. Example: Suppose, the input is: JJJJJ Guess what output is? Well, the output is: JJJJJ. Do you see it? Exactly. It doesn't encrypt the characters that have no difference in their ascii value. Well, you can't expect too much from a 12 line program. ''' import math string = input("Enter your string to be encrypted: ") # Getting the input. encrypted = "" # Initialising the empty string. print() for i in range(len(string) - 1): char_encrypt = ord(string[i]) # Getting the ascii value of the current character. next_char = ord(string[i + 1]) # Getting the ascii value of the next character. diff_val = int(math.fabs(next_char - char_encrypt)) # Calculating the difference in the ascii values. req_char = char_encrypt + 2 * diff_val encrypted += chr(req_char) # Adding the character into the string. encrypted += string[-1] # Adding the last character of the string. print(encrypted) print(len(encrypted)) # NOTE: Sometimes this program can give ABSOLUTELY fucking weird outputs. Example: Motherfucker ----(encrypting)---> ynswr # Thank you for checking out my program. # PROGRAM BY 'JAMES COLLINS'
run
|
edit
|
history
|
help
0
denemeler
Lab_I_4_25_11_2020
Sieve of Eratosthenes
Print lists separated by comma
pyFoodTipFoodOrder
T
square cube function
Game4
PyRegFindFull
ElaineBrown** rextester.com