Last active
August 25, 2017 14:57
-
-
Save Jcpetrucci/5965a2682809d0f0f30c779df2c40779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script converts the hexadecimal represenatation of an SSH (or similar) key's fingerprint into friendly words. The goal is to allow humans to more easily recognize when a fingerprint changes. | |
# Usage: provide the hexadecimal fingerprint as standard input. The regex match should trim any excess, so you do not have to be too precise when doing this. Just make sure that the fingerprint echoed back matches what you expect. | |
# This version was made in a pinch and has room for improvement. | |
# Example: | |
# $ ssh-keygen -l -f ~/.ssh/id_rsa | ./hex-fingerprint-words | |
# Generating from input fingerprint: 3b:44:c7:20:21:8c:81:5b:af:6a:da:bd:ab:29:c9:4f | |
# CONSENSUS DASHBOARD SHAMROCK BOTTOMLESS BRADBURY MOLECULE KLAXON EXAMINE RACKETEER GOLDFISH SURMOUNT RINGBOLT PUPIL CANNONBALL SLINGSHOT DRIFTER | |
word_bank=( | |
aardvark | |
accrue | |
adrift | |
adult | |
afflict | |
aggregate | |
aimless | |
alkali | |
almighty | |
ammo | |
amusement | |
antenna | |
apple | |
armistice | |
artist | |
asteroid | |
Atlantic | |
atmosphere | |
Aztec | |
Babylon | |
backward | |
banjo | |
beaming | |
beehive | |
befriend | |
belowground | |
bifocals | |
bison | |
blockade | |
bluebird | |
bombast | |
bookshelf | |
bottomless | |
Bradbury | |
Brazilian | |
breakaway | |
brickyard | |
Burbank | |
businessman | |
button | |
Camelot | |
cannonball | |
caravan | |
celebrate | |
cement | |
chairlift | |
chatter | |
Cherokee | |
chisel | |
chopper | |
clamshell | |
classroom | |
clergyman | |
cobra | |
combustion | |
commence | |
component | |
concurrent | |
conformist | |
consensus | |
corporate | |
councilman | |
crackdown | |
crossover | |
crucial | |
crumpled | |
cubic | |
customer | |
dashboard | |
decadence | |
decimal | |
designing | |
detergent | |
dictator | |
direction | |
disbelief | |
distortion | |
dogsled | |
drainage | |
drifter | |
drumbeat | |
Dupont | |
eating | |
egghead | |
embezzle | |
endorse | |
enlist | |
enterprise | |
equipment | |
escapade | |
Eskimo | |
examine | |
existence | |
eyeglass | |
facial | |
fascinate | |
finicky | |
flatfoot | |
forever | |
fracture | |
freedom | |
frighten | |
Galveston | |
Geiger | |
glitter | |
glucose | |
goldfish | |
graduate | |
gremlin | |
guitarist | |
Hamilton | |
handiwork | |
headwaters | |
hesitate | |
highchair | |
holiness | |
hydraulic | |
impetus | |
indigo | |
indulge | |
infancy | |
informant | |
insurgent | |
intention | |
inverse | |
island | |
Jamaica | |
Jupiter | |
kickoff | |
klaxon | |
letterhead | |
locale | |
maritime | |
maverick | |
megaton | |
microscope | |
midsummer | |
minnow | |
miser | |
Mohawk | |
molecule | |
monument | |
mural | |
narrative | |
necklace | |
newborn | |
nightbird | |
Oakland | |
October | |
Ohio | |
optic | |
orca | |
outfielder | |
pandemic | |
paperweight | |
paragraph | |
passenger | |
peachy | |
Pegasus | |
perceptive | |
pharmacy | |
phonetic | |
physique | |
playhouse | |
pocketful | |
positive | |
preclude | |
preshrunk | |
processor | |
prowler | |
puberty | |
pupil | |
pyramid | |
quadrant | |
quiver | |
racketeer | |
ratchet | |
rebirth | |
recover | |
regain | |
rematch | |
repellent | |
reproduce | |
responsive | |
retraction | |
retrospect | |
revenue | |
revolver | |
rhythm | |
ringbolt | |
rocker | |
sailboat | |
sardonic | |
savagery | |
scallion | |
scenic | |
Scotland | |
select | |
sentence | |
shamrock | |
skullcap | |
slingshot | |
snapline | |
snowcap | |
sociable | |
southward | |
soybean | |
spearhead | |
speculate | |
spheroid | |
spindle | |
stagehand | |
stairway | |
stapler | |
sterling | |
stockman | |
stormy | |
sugar | |
surmount | |
suspense | |
sweatband | |
sympathy | |
talon | |
tapeworm | |
tempest | |
tiger | |
tobacco | |
tomorrow | |
topmost | |
tracker | |
transit | |
travesty | |
Trojan | |
trouble | |
tumor | |
tycoon | |
ultimate | |
undaunted | |
unearth | |
unify | |
unravel | |
upcoming | |
upset | |
vacancy | |
vapor | |
village | |
virus | |
vocalist | |
Vulcan | |
wallet | |
watchword | |
wayside | |
Wichita | |
Wilmington | |
Wyoming | |
Yucatan | |
) | |
while IFS= read -r hex_fingerprint; do # Read a line of standard input | |
hex_fingerprint="$(grep -Eio '([a-f0-9]{2}:)+[a-f0-9]{2}' <<<"$hex_fingerprint" )" || continue # If the line contains something that looks like hex, then try to parse it | |
printf '%s %s\n' 'Generating from input fingerprint:' "$hex_fingerprint" # Print the string that looks like hex for added feedback | |
hex_buffer=$hex_fingerprint # Initialize a buffer to work with, contents equal the hex string | |
while (( ${#hex_buffer} >= 2 )); do # While there are at least two characters of hex... | |
hex_byte=${hex_buffer:0:2} # Take the first two characters | |
dec_byte=$(printf '%d' "0x${hex_byte}") # Get the decimal value | |
printf '%-12s' ${word_bank[$dec_byte]^^} # Print from the word bank at that position | |
(( ${#hex_buffer} == 2 )) && break # If these were the last two characters of the hex string, stop | |
hex_buffer=${hex_buffer#$hex_byte":"} # Remove the current byte and its tailing colon from the beginning of the buffer | |
done | |
printf '\n' | |
done < /proc/self/fd/0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment