Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- def main():
- if len(sys.argv) > 1:
- registers = sys.argv[1]
- else:
- registers = '1001'
- # Ensure only 1's and 0's are present
- for reg in registers:
- if reg not in '01':
- print('Must only use 1s and 0s', file=sys.stderr)
- sys.exit(1)
- # Convert registers to a list of ints
- registers = [int(x) for x in registers]
- output = ""
- for i in range(0, 15):
- # Display the registers before any manipulation
- print("[registers]", *registers, end=" ")
- # XOR the last 2 registers
- r1 = registers[-2]
- r2 = registers[-1]
- xor = r1 ^ r2
- # Add the last register to the end of the output
- output += str(registers.pop())
- # Display infoz
- print("[xor]", "{} ^ {} = {}".format(r1, r2, xor), end=" ")
- print("[output]", output)
- # Insert the XOR result to the beginning of the registers
- registers.insert(0, xor)
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment