fork download
  1. r = dict(zip('\\qwertyuio\'asdfghjkl;/zxcvbnm|:"?', 'qwertyuiopasdfghjkl;\'zxcvbnm,Q"AZ'))
  2. l = dict(zip('wertyuiop[\'asdfghjkl;xcvbnm,.{:"<', 'qwertyuiop;\'asdfghjklzxcvbnm,PL:M'))
  3. shifts = {'right': r, 'left': l}
  4.  
  5. def shift(ciphered):
  6. letters = set(ciphered)
  7. if letters & set('p[{,<') or any(i in ciphered for i in ('yjr', 'smf')):
  8. return 'left'
  9. elif letters & set('qz\\|/?') or any(i in ciphered for i in ('rgw', '\'bs')):
  10. return 'right'
  11. else:
  12. return 'right' if ciphered.count('w') > ciphered.count('y') else 'left'
  13.  
  14. def decipher(ciphered):
  15. ciphered = ciphered.split('.', 1)[0].lower()
  16. shift_ = shift(ciphered)
  17. text = ''.join(shifts[shift_].get(i, i) for i in ciphered).capitalize()
  18. print 'text:', text + '.'
  19. print 'offset:', 'left' if shift_ == 'right' else 'right'
  20.  
  21. for _ in range(6):
  22. decipher(raw_input())
Success #stdin #stdout 0.09s 8840KB
stdin
Upi djpi;f ytu yu[omh pmr yp yjr ;rgy.
U kujw oeife'nnubf xibrwara.
X'ra 'bs sifa 'ew ai o'aaw.
Yjod vpmysod sm stnoysto;u ;pmh eptf.
Rgw x'r ;b rgw g'r qwbr iyr ri v'r.
Og upi vtrsyr s d,s;; fovyopmstu pg yjr ,pdy vp,,pm rmh;odj eptfd yjrm upi vsm vjrvl upit piy[iy gpt yjpdr eptfd' yjr eptf ayjra smf yjr eptf asmfa str imowir ejrm pggdry ;rgy smf pggdry tohjy. //<< don't put this deciphered text in your answers.
stdout
text: You should try typing one to the left.
offset: right
text: I like programming contests.
offset: left
text: Cats and dogs are so passe.
offset: left
text: This contais an arbitarily long word.
offset: right
text: The cat 'n the hat went out to bat.
offset: left
text: If you create a small dictionary of the most common english words then you can check your output for those words; the word 'the' and the word 'and' are unique when offset left and offset right.
offset: right