Skip to content

Instantly share code, notes, and snippets.

@jabb3rd
Created December 8, 2017 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jabb3rd/07aa88688583469217be1bdff0812da6 to your computer and use it in GitHub Desktop.
Save jabb3rd/07aa88688583469217be1bdff0812da6 to your computer and use it in GitHub Desktop.
Keyboard walker
#!/usr/bin/env python
layout = [
['1234567890-=', 'qwertyuiop[]', 'asdfghjkl;\'\\', 'zxcvbnm,./'],
['!@#$%^&*()_+', 'QWERTYUIOP{}', 'ASDFGHJKL:"|', 'ZXCVBNM<>?']
]
def get_char(xy, shift = 0):
x, y = xy;
return layout[shift][x][y]
def right(xy):
x, y = xy
y += 1
if y > len(layout[0][x]) - 1:
y = 0
return (x, y)
def left(xy):
x, y = xy
y -= 1
if y < 0:
y = len(layout[0][x]) - 1
return (x, y)
def down(xy):
x, y = xy
x += 1
if x > len(layout[0]) - 1:
x = 0
if y > len(layout[0][x]) - 1:
x, y = down((x, y))
return (x, y)
def up(xy):
x, y = xy
x -= 1
if x < 0:
x = len(layout[0]) - 1
if y > len(layout[0][x]) - 1:
x, y = up((x, y))
return (x, y)
def up_left(xy):
return left(up(xy))
def up_right(xy):
return right(up(xy))
def down_left(xy):
return left(down(xy))
def down_right(xy):
return right(down(xy))
def shift(xy):
return xy
def loop(xy):
return xy
def double_left(xy):
return left(left(xy))
def double_right(xy):
return right(right(xy))
def double_up(xy):
return up(up(xy))
def double_down(xy):
return down(down(xy))
def double_up_right(xy):
return right(double_up(xy))
def double_up_left(xy):
return left(double_up(xy))
def generate_graph(xy, actions):
graph = []
shift_reg = 0
for action in actions:
if action == shift:
shift_reg = 1
else:
xy = action(xy)
dx, dy = xy
graph.append((dx, dy, shift_reg))
if shift_reg == 1:
shift_reg = 0
return graph
def generate_string(graph):
result = ''
for element in graph:
x, y, s = element
result += get_char((x, y), s)
return result
def generate_strings(template):
result = []
for x in range(len(layout[0])):
for y in range(len(layout[0][x])):
graph = generate_graph((x, y), template)
result.append(generate_string(graph))
return result
template = [loop, down, up_right, down, up_right, down, up_right, down]
strings = generate_strings(template)
print(strings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment