Keyboard Encryption

3

Challenge

Given a string with any characters a-z or A-Z, return an 'encrypted' string, where all characters are replaced by the character next to it (assuming a QWERTY keyboard).

  • Case (uppercase, lowercase) does not matter.
  • The input will only have characters a-z and A-Z.

Shortest code in bytes wins.


Example Input and Output

Foo Foo Bar Bar PythonGpp Gpp Nst Nst [uyjpm

Case does not mattervSDR fprd mpy ,sYYrT

Matias K

Posted 2017-03-19T02:42:43.940

Reputation: 283

Question was closed 2017-03-19T04:32:07.583

Seems like a subset of this challenge.

– Jonathan Allan – 2017-03-19T02:47:42.500

Looks fairly nice to me. have a +1 :) – Matthew Roh – 2017-03-19T03:06:44.480

Well at least Jelly would be non-competing there – Jonathan Allan – 2017-03-19T03:09:23.630

"The input will only have characters a-z and A-Z.": should this also say "and " – micsthepick – 2017-03-19T03:33:42.013

Looks like it's more of a dupe of this

– Okx – 2017-03-19T13:53:48.630

Answers

2

Jelly, 16 bytes

ŒlµØqż“[;,”Fṡ2Zy

Try it online!

How?

ŒlµØqż“[;,”Fṡ2Zy - Main link: string
Œl               - convert to lowercase
  µ              - monadic chain separation
   Øq            - qwerty yield: ["qwertyuiop","asdfghjkl","zxcvbnm"]
      “[;,”      - "[;,"
     ż           - zip: [["qwertyuiop","["],["asdfghjkl",";"],["zxcvbnm",","]
           F     - flatten: "qwertyuiop[asdfghjkl;zxcvbnm,"
            ṡ2   - overlapping pairs: ["qw","we","er","rt","ty","yu","ui","io","op","p[","[a","as","sd","df","fg","gh","hj","jk","kl","l;",";z","zx","xc","cv","vb","bn","nm","m,"]
              Z  - transpose: ["qwertyuiop[asdfghjkl;zxcvbnm","wertyuiop[asdfghjkl;zxcvbnm,"]
               y - translate the lowercased string with that mapping

Jonathan Allan

Posted 2017-03-19T02:42:43.940

Reputation: 67 804

1

Python 3, 91 bytes:

s='qwertyuiop[asdfghjkl;zxcvbnm,  ' 
print(''.join(s[s.index(c)+1]for c in input().lower()))

micsthepick

Posted 2017-03-19T02:42:43.940

Reputation: 421

Can remove two bytes if there is no space in input... – micsthepick – 2017-03-19T03:30:16.747