+ 4
How do i do this?
def abstash_cipher(plaintext): Ex) abstash_cipher(“abcd”) should be ‘zxyw’ its in python Got to use a loop cannot use reverse
2 Respuestas
+ 10
The first thing which comes to mind is using list operations.
def abstash_cipher(plaintext):
return ''.join([chr(ord(x)+25-((ord(x)-97)*2)) for x in list(plaintext.lower())])
print(abstash_cipher("abcdefghijk"))
This doesn't involve loops, but should give you a good idea of what to use, e.g. ord(), chr(), and the underlying conversion logic.
Ofc, if you want to simplify the equation, you can use:
return ''.join([chr(-ord(x)+219) for x in list(plaintext.lower())])
which is equivalent to the above.
+ 4
This is in Java, but the method shiftAlphabet can help:
https://code.sololearn.com/cA316qa8j600/?ref=app