java.lang.Object
net.i2p.imagegen.RandomArt

public class RandomArtextends Object
Draw an ASCII-Art representing the fingerprint so human brain can profit from its built-in pattern recognition ability. This technique is called "random art" and can be found in some scientific publications like this original paper. "Hash Visualization: a New Technique to improve Real-World Security", Perrig A. and Song D., 1999, International Workshop on Cryptographic Techniques and E-Commerce (CrypTEC '99) sparrow.ece.cmu.edu/~adrian/projects/validation/validation.pdf The subject came up in a talk by Dan Kaminsky, too. If you see the picture is different, the key is different. If the picture looks the same, you still know nothing. The algorithm used here is a worm crawling over a discrete plane, leaving a trace (augmenting the field) everywhere it goes. Movement is taken from dgst_raw 2bit-wise. Bumping into walls makes the respective movement vector be ignored for this turn. Graphs are not unambiguous, because circles in graphs can be walked in either direction.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    Characters of the ASCII symbol field.
    private static final char
    ASCII box border, bottom left.
    private static final char
    ASCII box border, bottom.
    private static final char
    ASCII box border, bottom right.
    private static final char
    ASCII box border, left.
    private static final char
    ASCII box border, right.
    private static final char
    ASCII box border, top left.
    private static final char
    ASCII box border, top.
    private static final char
    ASCII box border, top right.
    private static final int
    Base of the symbol field values.
    private static final int
    Width of the symbol field.
    private static final int
    Height of the symbol field.
    private static final String
    Characters of the Unicode symbol field.
    private static final char
    Unicode box border, bottom left.
    private static final char
    Unicode box border, bottom.
    private static final char
    Unicode box border, bottom right.
    private static final char
    Unicode box border, left.
    private static final char
    Unicode box border, right.
    private static final char
    Unicode box border, top left.
    private static final char
    Unicode box border, top.
    private static final char
    Unicode box border, top right.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The field geometry, the glyph strings and the render() entry points are all static, so an instance carries no state of its own.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static String
    getColor(long base, int mod)
    Chooses the color for a value.
    static String
    gnutls_key_fingerprint_randomart(byte[] dgst_raw, String key_type, int key_size, String prefix, boolean unicode, boolean html)
    Render a digest as the dr randomness "random art" block.
    static void
    main(String[] args)
    Print a sample random art rendering, as an HTML page.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • RandomArt

      public RandomArt()
      The field geometry, the glyph strings and the render() entry points are all static, so an instance carries no state of its own.
  • Method Details

    • gnutls_key_fingerprint_randomart

      public static String gnutls_key_fingerprint_randomart(byte[] dgst_raw, String key_type, int key_size, String prefix, boolean unicode, boolean html)
      Render a digest as the dr randomness "random art" block.
      Parameters:
      dgst_raw - the data to be visualized, recommend 64 bytes or less
      key_type - output in the first line, recommend 6 chars or less
      key_size - output in the first line
      prefix - if non-null, prepend to every line
      unicode - true to draw with Unicode box characters, not ASCII ones
      html - true to emit coloured div/pre HTML with a span per cell
      Returns:
      the rendered random art, HTML when html is true, else plain text
    • getColor

      private static String getColor(long base, int mod)
      Chooses the color for a value.
      Parameters:
      base - the value to color
      mod - the modulus applied first
      Returns:
      the color name
    • main

      public static void main(String[] args)
      Print a sample random art rendering, as an HTML page.
      Parameters:
      args - ignored; the sample digest is fixed in the body