3
\$\begingroup\$

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

\$\endgroup\$
5
  • \$\begingroup\$ Seems like a subset of this challenge. \$\endgroup\$ Commented Mar 19, 2017 at 2:47
  • \$\begingroup\$ Looks fairly nice to me. have a +1 :) \$\endgroup\$ Commented Mar 19, 2017 at 3:06
  • \$\begingroup\$ Well at least Jelly would be non-competing there \$\endgroup\$ Commented Mar 19, 2017 at 3:09
  • \$\begingroup\$ "The input will only have characters a-z and A-Z.": should this also say "and ` `" \$\endgroup\$ Commented Mar 19, 2017 at 3:33
  • \$\begingroup\$ Looks like it's more of a dupe of this \$\endgroup\$
    – Okx
    Commented Mar 19, 2017 at 13:53

2 Answers 2

1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

Python 3, 91 bytes:

s='qwertyuiop[asdfghjkl;zxcvbnm,  ' 
print(''.join(s[s.index(c)+1]for c in input().lower()))
\$\endgroup\$
1
  • \$\begingroup\$ Can remove two bytes if there is no space in input... \$\endgroup\$ Commented Mar 19, 2017 at 3:30