A seven-segment display1 is a form of electronic device for displaying decimal numerals (sometimes also hexadecimal letters). Calculator spelling2 is an unintended characteristic of the seven-segment display, in which the digits resemble letters of the Latin alphabet when read upside-down. As a result each digit is mapped onto a letter, creating a limited but functional subset of the alphabet, sometimes referred to as beghilosz.

7-segmentdisplay
Example of a 7-segmentdisplay with LED.

The basic step of calculator spelling consists of mapping each digit onto a letter, resulting in the representation of words on a calculator display whose letters are taken from a subset of the alphabet. This is the default mapping of digits onto letters:

digit 0 1 2 3 4 5 6 7 8
letter O I Z E h S g L B

The graphic below illustrates the term BEghILOSZ constructed from the inverted sequence 250714638:

beghilosz

Certain calculators omit the topmost stem on the digit 6 and the bottom-most stem on the 9. In such cases, 6 renders a lowercase q when turned upside-down, and 9 appears as a lowercase b. Extending the available alphabet to hexadecimal notation3 (generally available on lower-end scientific calculators, though not on basic models), b and d correspond to q and p respectively.

digit 0 1 2 3 4 5 6 7 8 9 A b C d E F
letter O I Z E h S g L B b Y q J P 3 j

Placing a calculator in front of a mirror produces the following mapping:

digit 0 1 2 3 4 5 6 7 8 9 A b C d E F
letter O I S E y Z a r B e A d J b 3 z

Assignment

An alphabet is represented as a string in which each character occurs at most once. Your task:

Example

>>> c2l = digits2letters('012345678', 'OIZEhSgLB')
>>> c2l
{'1': 'I', '0': 'O', '3': 'E', '2': 'Z', '5': 'S', '4': 'h', '7': 'L', '6': 'g', '8': 'B'}

>>> beghilosz2text('250714638', c2l)
'BEghILOSZ'
>>> beghilosz2text('3722145', c2l)
'ShIZZLE'
>>> beghilosz2text('53177187714', c2l)
'hILLBILLIES'

>>> l2c = letters2digits(c2l)
>>> l2c
{'B': '8', 'E': '3', 'g': '6', 'I': '1', 'h': '4', 'L': '7', 'O': '0', 'S': '5', 'Z': '2'}

>>> text2beghilosz('BEghILOSZ', l2c)
'250714638'
>>> text2beghilosz('SHIZZLE', l2c)
'3722145'
>>> text2beghilosz('hillbillies', l2c)
'53177187714'

Epilogue

In the November 2010 Word Ways4, Mike Keith notes a striking coincidence:

Bible's Machine and Welding
6499 Blue Springs Pkwy
Mosheim, TN 37818

That' the address of a machine shop5 in eastern Tennessee (US), presumably owned by a family named Bible. Enter the zip code in a calculator and turn it upside down.