MyNixOS website logo
Description

An implementation of the Drunken Bishop visual fingerprinting algorithm.

The Drunken Bishop algorithm is a visual fingerprinting algorithm originally implemented by OpenSSH for visualizing key fingerprints. This package implements OpenSSH's visualization while also offering extra configuration to allow for specialized uses.

The Drunken Bishop algorithm was designed heuristically, and therefore should not be considered cryptographically strong.

drunken-bishop

The Drunken Bishop algorithm is a visual fingerprinting algorithm originally implemented by OpenSSH for visualizing key fingerprints. This package implements OpenSSH's visualization while also offering extra configuration to allow for specialized uses.

Basic usage

The Data.Digest.DrunkenBishop(drunkenBishop) function takes a bytestring and produces a multiline string representing the visualization of the hash of that string.

>>> :set -XOverloadedStrings
>>> putStrLn (drunkenBishop "hello!")

             .
          . o
         = o
      . ^ B .
       o = . o +
        ..+.+ = E
         +o..=
         ..  ..

Configurable usage

The Data.Digest.DrunkenBishop(DrunkenBishopOptions) type contains several fields which can be configured to change the operation of the algorithm. The default used by the drunkenBishop function are kept in an instance of this type called drunkenBishopDefaultOptions.

The drunkenBishopBoardSize field can set the size of the overall fingerprint image. Note that smaller images will produce "noisier" fingerprints, while larger images will likely produce "sparser" fingerprints.

> :set -XOverloadedStrings
> let opts = drunkenBishopDefaultOptions { drunkenBishopBoardSize = (9, 9) }
> putStrLn (drunkenBishopWithOptions opts "hello!")

        .
      ...
    .+..
  . ^++.
   o.=.oo
 .o.+ =.E
 oo..=  .
 ..  ..

The drunkenBishopInitialPosition field can change the initial position of the bishop:

> :set -XOverloadedStrings
> let opts = drunkenBishopDefaultOptions { drunkenBishopInitialPosition = Just (0, 0) }
> putStrLn (drunkenBishopWithOptions opts "hello!")
S .   ..
 . o ..
o o.+.
.. ++ .
  .... . o
   .  ..o..
   .o.ooo E
   oo..o.
   ..  .

The drunkenBishopCharMap field can change the ASCII visualizer used for the cells of the visualization algorithm:

> :set -XOverloadedStrings
> import Data.Char (chr)
> let opts = drunkenBishopDefaultOptions { drunkenBishopCharMap = \ c -> chr (fromIntegral (c + 65)) }
> putStrLn (drunkenBishopWithOptions opts "hello!")
AAAAAAAAAAAAAAAAA
AAAAAAAAAAAAABAAA
AAAAAAAAAABACAAAA
AAAAAAAAAEACAAAAA
AAAAAABAOAGABAAAA
AAAAAAACAEABACADA
AAAAAAAABBDBDAEAQ
AAAAAAAAADCBBEAAA
AAAAAAAAABBAABBAA

Finally, the drunkenBishopHash field can change the hash function used by the Drunken Bishop algorithm. This is parametric and can take any type, but must produce a strict ByteString. Note that the default MD5 hash produces 128-bit values, so hash functions that produce more values will produce considerably "noisier" fingerprints unless you also change the fingerprint size. The following example uses hashlazy from the cryptohash-sha256 package as an example:

> :set -XOverloadedStrings
> import Crypto.Hash.SHA256 (hashlazy)
> let opts = drunkenBishopDefaultOptions { drunkenBishopHash = hashlazy }
> putStrLn (drunkenBishopWithOptions opts "hello!")
           .oo+
   .        .= o
  . o   .   o + .
   o . = . . = ..
  . = = ^ . . =o
   = + o +.    o+
    o ooo=.o  . o
   .  ..= =.o  o.
      .o.E.. o...

The drunken-bishop executable

The accompanying drunken-bishop executable takes a list of files, or if none are provided, a string on stdin, runs it through the fingerprinting routine, and prints it with a simple ASCII art frame. It accepts a few of the configuration options described above, as well.

$ printf "hello!" | drunken-bishop
+-----------------+
|                 |
|             .   |
|          . o    |
|         = o     |
|      . ^ B .    |
|       o = . o + |
|        ..+.+ = E|
|         +o..=   |
|         ..  ..  |
+-----------------+
$ printf "hello!" | drunken-bishop --sha256
+-----------------+
|           .oo+  |
|   .        .= o |
|  . o   .   o + .|
|   o . = . . = ..|
|  . = = ^ . . =o |
|   = + o +.    o+|
|    o ooo=.o  . o|
|   .  ..= =.o  o.|
|      .o.E.. o...|
+-----------------+
Metadata

Version

0.1.0.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows