Skip to content

Instantly share code, notes, and snippets.

@ldong
Last active January 26, 2023 07:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ldong/9921248 to your computer and use it in GitHub Desktop.
Save ldong/9921248 to your computer and use it in GitHub Desktop.
Python Challenge walkthrough

Python Challenge

Click here to play Python Challenge

If you cannot solve this one, please stop reading right now.

K->M, O->M, E->G

The difference between A->B is 2

There're two ways to approach it.

A.

def convert(str):
  print chr(ord(str) + 2)
b = 'g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.'
for i in b:
  convert(i)

However as you can see, the output is messy because it also converted the white space and dots into other characters unintentionally.

i " h o p e " y o u " d i d n t " t r { n s l { t e " i t " | y " h { n d 0 " t h { t s " w h { t " c o m p u t e r s " { r e " f o r 0 " d o i n g " i t " i n " | y " h { n d " i s " i n e f f i c i e n t " { n d " t h { t ) s " w h y " t h i s " t e x t " i s " s o " l o n g 0 " u s i n g " s t r i n g 0 m { k e t r { n s * + " i s " r e c o m m e n d e d 0 " n o w " { p p l y " o n " t h e " u r l 0

B. Using this is much cleaner and neat. maketrans

from string import maketrans 
int = "abcdefghijklmnopqrstuvwxyz"
out = "cdefghijklmnopqrstuvwxyzab"
trans_int_out = maketrans(int, out)
print b.translate(trans_int_out)
### output
"i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url."

Like the output asked, apply translate on "map".

b='map'
print b.translate(trans_int_out)
orc

View this page's source will see something commented out like this

<!-- find rare characters in the mess below: -->

strip off the <!-- --> and save on disk, then go ahead and run the script here

You will get "equality", and let's copy and paste it on the browser.

@didi-21
Copy link

didi-21 commented Aug 21, 2021

this way works too

puzzle = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
deez = ""
for word in puzzle :
if ord(word) > 96 and ord(word) < 121 :
deez += (chr(ord(word)+2))
elif ord(word) == 121 : deez += 'a'
elif ord(word) == 122 : deez += 'b'
elif ord(word) > 31 and ord(word) < 48 :
deez += word
print(deez)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment