Guest User

Untitled

a guest
Dec 10th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. layout = [
  4. ['1234567890-=', 'qwertyuiop[]', 'asdfghjkl;\'\\', 'zxcvbnm,./'],
  5. ['!@#$%^&*()_+', 'QWERTYUIOP{}', 'ASDFGHJKL:"|', 'ZXCVBNM<>?']
  6. ]
  7.  
  8. def get_char(xy, shift = 0):
  9. x, y = xy;
  10. return layout[shift][x][y]
  11.  
  12. def right(xy):
  13. x, y = xy
  14. y += 1
  15. if y > len(layout[0][x]) - 1:
  16. y = 0
  17. return (x, y)
  18.  
  19. def left(xy):
  20. x, y = xy
  21. y -= 1
  22. if y < 0:
  23. y = len(layout[0][x]) - 1
  24. return (x, y)
  25.  
  26. def down(xy):
  27. x, y = xy
  28. x += 1
  29. if x > len(layout[0]) - 1:
  30. x = 0
  31. if y > len(layout[0][x]) - 1:
  32. x, y = down((x, y))
  33. return (x, y)
  34.  
  35. def up(xy):
  36. x, y = xy
  37. x -= 1
  38. if x < 0:
  39. x = len(layout[0]) - 1
  40. if y > len(layout[0][x]) - 1:
  41. x, y = up((x, y))
  42. return (x, y)
  43.  
  44. def up_left(xy):
  45. return left(up(xy))
  46.  
  47. def up_right(xy):
  48. return right(up(xy))
  49.  
  50. def down_left(xy):
  51. return left(down(xy))
  52.  
  53. def down_right(xy):
  54. return right(down(xy))
  55.  
  56. def shift(xy):
  57. return xy
  58.  
  59. def loop(xy):
  60. return xy
  61.  
  62. def double_left(xy):
  63. return left(left(xy))
  64.  
  65. def double_right(xy):
  66. return right(right(xy))
  67.  
  68. def double_up(xy):
  69. return up(up(xy))
  70.  
  71. def double_down(xy):
  72. return down(down(xy))
  73.  
  74. def double_up_right(xy):
  75. return right(double_up(xy))
  76.  
  77. def double_up_left(xy):
  78. return left(double_up(xy))
  79.  
  80. def generate_graph(xy, actions):
  81. graph = []
  82. shift_reg = 0
  83.  
  84. for action in actions:
  85. if action == shift:
  86. shift_reg = 1
  87. else:
  88. xy = action(xy)
  89. dx, dy = xy
  90. graph.append((dx, dy, shift_reg))
  91. if shift_reg == 1:
  92. shift_reg = 0
  93. return graph
  94.  
  95. def generate_string(graph):
  96. result = ''
  97. for element in graph:
  98. x, y, s = element
  99. result += get_char((x, y), s)
  100. return result
  101.  
  102. def generate_strings(template):
  103. result = []
  104. for x in range(len(layout[0])):
  105. for y in range(len(layout[0][x])):
  106. graph = generate_graph((x, y), template)
  107. result.append(generate_string(graph))
  108. return result
  109.  
  110. template = [loop, down, up_right, down, up_right, down, up_right, down]
  111. strings = generate_strings(template)
  112. print(strings)
Add Comment
Please, Sign In to add comment