Challenge: take ciphered text and decipher, also print out if it was offset to the left or right Problem:

Take input text like this: (all input should be considered strings)

 Upi djpi;f ytu yu[omh pmr yp yjr ;rgy.


And figure out if it was offset left or offset right (on a standard qwerty keyboard as pictured below). 

Also only keys that output something to the screen are considered valid, so these keys: caps, shift, tab, enter, delete(backspace), should not be considered when doing this challenge. 



Once you have figured out what the offset is, print out the offset and the correct text.

For example the above input would have this output

 text: You should try typing one to the left.
 offset: right


Your program has to 'know' that the sentence is correct before it prints out. (so no asking for user verification). Also no using libraries (should be a given).

All input will begin with a capital and end in a period (the period will not be offset left or right so you won't be able to use it to determine the offset.)

Another example:

U kujw oeife'nnubf xibrwara.

I like programming contests. 


Some input samples to use:

 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. //&lt;&lt; don't put this deciphered text in your answers. 


And bonus option: write your program to be able to handle the input switching offsets. 

Example above with switching offset:

Upi djpi;f ytu yu[omh ibw ri rgw kwdr.

text: You should try typing one to the left. 
offset: right -&gt; index[21], then left.


Winning criterion:


Faster code gets more points (out of 10) so O(logn) would score more then O(n^2) solutions (obviously).
Elegance (out of 20) There is a very elegant and simple solution to this problem. The closer you get to the simple solution the higher your score. (bonus +5 if you think of something simpler then my solution).
This is not a code golf, but concise readable code will be scored (out of 10).
Bonus is all or nothing for 5 extra points.


So A perfect score would be 40 but you could score up to 50 if you get both bonuses. 

bonus +2 if you read all instructions
Python

The original version didn't deal with punctuation too well, so here's a revised version.

r = dict(zip('\\qwertyuio\'asdfghjkl;/zxcvbnm|:"?', 'qwertyuiopasdfghjkl;\'zxcvbnm,Q"AZ'))
l = dict(zip('wertyuiop[\'asdfghjkl;xcvbnm,.{:"&lt;', 'qwertyuiop;\'asdfghjklzxcvbnm,PL:M'))
shifts = {'right': r, 'left': l}

def shift(ciphered):
    letters = set(ciphered)
    if letters &amp; set('p[{,&lt;') or any(i in ciphered for i in ('yjr', 'smf')):
        return 'left'
    elif letters &amp; set('qz\\|/?') or any(i in ciphered for i in ('rgw', '\'bs')):
        return 'right'
    else:
        return 'right' if ciphered.count('w') &gt; ciphered.count('y') else 'left'

def decipher(ciphered):
    ciphered = ciphered.split('.', 1)[0].lower()
    shift_ = shift(ciphered)
    text = ''.join(shifts[shift_].get(i, i) for i in ciphered).capitalize()
    print 'text:', text + '.'
    print 'offset:', 'left' if shift_ == 'right' else 'right'

decipher(raw_input())


This is how it works:


If any of the characters p[{,&lt; are in the ciphered string, or yjr or smf (the and and shifted right respectively) are in the string, then the string must have been shifted right.
If any of the characters qz\|/? are in the ciphered string, or rgw or 'bs (the and and shifted left respectively) are in the string, then the string must have been shifted left.
If neither of the above are true, then we compare the counts of 'w' and 'y' in the string. If there are more 'w's, then it is most likely to have been shifted left, because 'e' is more common than 'u' in English. If not, then it probably would have been shifted right, since 't' is much more common than 'q' in English.

The original function used 'w' and 's', however using e/u and q/t will theoretically produce much stabler results, as the frequency differences between the letter pairs are higher than those of the original e/d and q/a.
This will work for most strings, however theoretically there might be some strings who will give the wrong output. (If you find one, post the offender in the comments and I will try to make the test more stable)

We reverse-shift the string accordingly, to produce the output.


Note that if there is a comma in a string that has been shifted right (ie there is a . in the ciphered string excluding the one at the end), then this will not work, as the function only deciphers the part before the first period in the string.

Here are some sample test results.