Skip to content

Instantly share code, notes, and snippets.

@gdoteof
Last active December 25, 2015 05:19
Show Gist options
  • Save gdoteof/6923944 to your computer and use it in GitHub Desktop.
Save gdoteof/6923944 to your computer and use it in GitHub Desktop.
Get the shifted/unshifted key for a standard US keyboard for each letter in a word
def shift_case(word)
lookup = {
'z' => 'Z',
'Z' => 'z',
'x' => 'X',
'X' => 'x',
'c' => 'C',
'C' => 'c',
'v' => 'V',
'V' => 'v',
'b' => 'B',
'B' => 'b',
'n' => 'N',
'N' => 'n',
'm' => 'M',
'M' => 'm',
',' => '<',
'<' => ',',
'.' => '>',
'>' => '.',
'/' => '?',
'?' => '/',
'a' => 'A',
'A' => 'a',
's' => 'S',
'S' => 's',
'd' => 'D',
'D' => 'd',
'f' => 'F',
'F' => 'f',
'g' => 'G',
'G' => 'g',
'h' => 'H',
'H' => 'h',
'j' => 'J',
'J' => 'j',
'k' => 'K',
'K' => 'k',
'l' => 'L',
'L' => 'l',
';' => ':',
':' => ';',
'\'' => '"',
'"' => '\'',
'q' => 'Q',
'Q' => 'q',
'w' => 'W',
'W' => 'w',
'e' => 'E',
'E' => 'e',
'r' => 'R',
'R' => 'r',
't' => 'T',
'T' => 't',
'y' => 'Y',
'Y' => 'y',
'u' => 'U',
'U' => 'u',
'i' => 'I',
'I' => 'i',
'o' => 'O',
'O' => 'o',
'p' => 'P',
'P' => 'p',
'[' => '{',
'{' => '[',
']' => '}',
'}' => ']',
'\\' => '|',
'|' => '\\',
'`' => '~',
'~' => '`',
'1' => '!',
'!' => '1',
'2' => '@',
'@' => '2',
'3' => '#',
'#' => '3',
'4' => '$',
'$' => '4',
'5' => '%',
'%' => '5',
'6' => '^',
'^' => '6',
'7' => '&',
'&' => '7',
'8' => '*',
'*' => '8',
'9' => '(',
'(' => '9',
'0' => ')',
')' => '0',
'-' => '_',
'_' => '-',
'=' => '+',
'+' => '=',
}
out = ""
word.split("").each do |letter|
out += lookup[letter]
end
out
end
testword = "boobly123?><'|\\"
puts testword, "reversed", shift_case(testword)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment