Skip to content

Instantly share code, notes, and snippets.

@noureddin
Created February 27, 2017 16:28
Show Gist options
  • Save noureddin/b30918b66dd18c9bdc851d1c454f62f9 to your computer and use it in GitHub Desktop.
Save noureddin/b30918b66dd18c9bdc851d1c454f62f9 to your computer and use it in GitHub Desktop.
Dvorak-QWERTY Converter
#!/usr/bin/python3
# translate dvorak to qwetry and vice versa
# thank you, tr; you're useless to me!
# usage:
# run it, and input a line of dvorak-encoded text, then press enter to get the qwerty-decoded one
# run it with any argument, and input a line of qwerty, then press enter to get dvorak
h = {}
h[']'] = '/'; h['}'] = '+'
h['['] = '='; h['{'] = '?'
h['='] = ']'; h['+'] = '}'
h['/'] = '['; h['?'] = '{'
h['l'] = 'p'; h['L'] = 'P'
h['r'] = 'o'; h['R'] = 'O'
h['c'] = 'i'; h['C'] = 'I'
h['g'] = 'u'; h['G'] = 'U'
h['f'] = 'y'; h['F'] = 'Y'
h['y'] = 't'; h['Y'] = 'T'
h['p'] = 'r'; h['P'] = 'R'
h['.'] = 'e'; h['>'] = 'E'
h[','] = 'w'; h['<'] = 'W'
h["'"] = 'q'; h['"'] = 'Q'
h['-'] = "'"; h['_'] = '"'
h['s'] = ';'; h['S'] = ':'
h['n'] = 'l'; h['N'] = 'L'
h['t'] = 'k'; h['T'] = 'K'
h['h'] = 'j'; h['H'] = 'J'
h['d'] = 'h'; h['D'] = 'H'
h['i'] = 'g'; h['I'] = 'G'
h['u'] = 'f'; h['U'] = 'F'
h['e'] = 'd'; h['E'] = 'D'
h['o'] = 's'; h['O'] = 'S'
h['a'] = 'a'; h['A'] = 'A'
h['z'] = '/'; h['Z'] = '?'
h['v'] = '.'; h['V'] = '>'
h['w'] = ','; h['W'] = '<'
h['m'] = 'm'; h['M'] = 'M'
h['b'] = 'n'; h['B'] = 'N'
h['x'] = 'b'; h['X'] = 'B'
h['k'] = 'v'; h['K'] = 'V'
h['j'] = 'c'; h['J'] = 'C'
h['q'] = 'x'; h['Q'] = 'X'
h[';'] = 'z'; h[':'] = 'Z'
import sys
if len(sys.argv) > 1: # any args are given
d = dict((v,k) for k,v in h.items())
# http://stackoverflow.com/questions/3221475/reverse-mapping-of-dictionary-with-python
else:
d = h
a = input()
for i in a:
if i in d:
print(d[i], end='')
else:
print(i, end='')
print()
@noureddin
Copy link
Author

noureddin commented Feb 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment