Skip to content

Code to drive the receipt printer in the Cloudflare London office that outputs randomness

License

Notifications You must be signed in to change notification settings

cloudflare/receipt-printer

Cloudflare Randomness Printer

The Cloudflare Randomness Printer prints on demand a 'receipt' containing the following:

  1. A random number less than 1,000,000

  2. A six word diceware password

  3. Three passwords that have 128-bits of entropy. One has just hexadecimal digits, one has alphanumerics and another printable ASCII.

  4. A random response from the Magic 8 Ball.

  5. A QR code containing the information from 1 to 4.

  6. A maze generated using Prim's Algorithm using a modified version of this code to make it more legible on the printer.

  7. A random Sudoku generated using a modified version of this code.

  8. The current UTC date and time in ISO8601 format.

The Printer

The specific printer used is a GSAN 5870W Thermal Receipt Printer but the code will work with other printers that handle the ESC/POS format (which is very common). This specific printer was only used because we had one lying around.

Random Source

The program uses /dev/urandom which is fed with entropy from Cloudflare's internal randomness source (such as lava lamps)

Button

The code above runs on a Raspberry Pi Model B with an LED and a button connected to two GPIO ports. Pressing the button simply executes ep.py. It uses code similar to this:

import RPi.GPIO as GPIO
import time, os

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(25, GPIO.OUT)

while True:
    input_state = GPIO.input(18)
    if input_state == False:
        GPIO.output(25, GPIO.HIGH)
        os.system("python ep.py")
        GPIO.output(25, GPIO.HIGH)
    time.sleep(0.01)

The button is connected between GND and GPIO18. The LED is connected between GND and GPIO25 with a 330 Ohm resistor to GND.

About

Code to drive the receipt printer in the Cloudflare London office that outputs randomness

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages