Signin
Identicon: Updated and Source Released

I've updated Daily with following identicon related changes:

  * Your identicon is shown in the comment form so you won't have to post a comment to see it.

  * ETag support now works to give my server some relief.

Persistent identicon changes require some database changes so expect some delay on that.

My implementation of identicon is written in Java so you'll have to port the code if you are not using java. If you are, it's just a matter of hooking up the servlet, set inetSalt init-parameter, and you are ready to go.

Anyway, here is the preliminary (pre-cleanup/pre-documentation) version of Identicon source code. License is simply Go-Nuts-With-It. If and when later versions are released, it's likely to adopt more formal license.

Documentation? You'll have to make do with this single sentence version for now (sorry): IdenticonRenderer renders identicons, IdenticonUtil has code that derives identicon code from IP address.

Update:

Since non-java folks are starting to port the code before it can be properly documented, allow me to describe the rendering code to help them with their task.

How to draw an Identicon

 

A 9-block is a small quilt using only 3 types of patches, out of 16 available, in 9 positions. Using the identicon code, 3 patches are selected: one for center position, one for 4 sides, and one for 4 corners.

Positions and Rotations

For center position, only a symmetric patch is selected (patch 1, 5, 9, and 16). For corner and side positions, patch is rotated by 90 degree moving clock-wise starting from top-left position and top position respectively. This means 2 bits out of identicon code is used o select the center patch, 4 bits each for corner and side patches, 2 bits each for starting rotation of corner and side patches. In the source, each block array contains 4 rotated versions of each patch. You can do the same or generate the rotated versions on the fly.

Coloring and Inverting 

I am using white background with a patch color selected using 15 bits from the identicon code, expending 5 bits for each color component (R, G, B) placed at high-end of the component value (bits << 3). 1 bit per patch is used for inversion, meaning selected color will be used as background and white used as the patch shape color. Note that patch 16 is just an inverted version of patch 1.

32 Bits

Adding it up, you are using 32 bits ((2 + 4 + 4 + 2 + 2) + (15 + 3)) to render an identicon.

Poorman's Anti-aliasing

While the shapes themselves can be rendered directly using anti-aliasing, I got better result from drawing a scaled up version then scaling down to requested size. Also it's faster this way and works with graphics toolkits without anti-aliasing support.

Let me know if you have any questions. BTW, I am going to add more types of patches, symmetries, and quilts in the near future which will make wider variations of identicons. Wild!


Update 2:

Charles Darke has implemented a variation called Visiglyph using PHP.

Comments
On IE, my CSS layout gets screwed up when a post contains indented text. It's in the todo pile somewhere.
Quick question. Is it being released as public domain or is there a more restrictive licence?
Public domain for now, Charles. In the future, LGPL is most likely since I don't like GPL much.
Thanks for clarifying. It probably won't matter to me anyway since it will probably be easier for me to recode it than try to read Java :p
BTW, only the identicon rendering code plus plain IP-identicon conversion code is being open sourced. This is to encourage use of identicon in as many applications as possible.

My particular use is related to identity and much of that code won't be open sourced.
You might hold off until I had a chance to clean up and document the code so you can easily see what's going on. As is, it's rather cryptic.
I'm going to try to write a PHP version since that's what most people use.
I started in on a Python port on the bus today. Hoping to have something shareable this weekend or early next week.
Edward, you beat me to it, I'd be interested in the python version once you have it available.
I've written a PHP implementation. Currently the glyphs are generated on-the-fly but I'm working on a cache. Please take a look at:

http://digitalconsumption.com/forum/180

It would be good to get some testing. Note that I used two colour glyphs which don't quite have the simplicity of a single colour glyph but they can store more information.
Great inspiration! I just released my "MonsterID" PHP code, based upon your idea and the Combinatoric Critters idea you linked to. Check it out at http://www.splitbrain.org/blog/2007-01/20_monsterid_as_gravatar_fallback
Nice avatar implementation. Also to update, my source code is now released at: http://digitalconsumption.com/forum/180
Groovy guys, just groovy.
Mauvaisours   at 2007/01/22 05:41:34 AM
Did you also notice that patch 2 rotated 180 degrees is the same as patch 2 inverted ? (note that this is also true for patch 4 ?)
It's difficult not to notice, Mauvaisours. Still, it is difficult to intentionally use someone else's identicon without sharing an IP address.
Mauvaisours   at 2007/01/23 03:05:02 AM
Sure, it is difficult to generate collisions when using a SHA1 hash, but it makes your algorithm bad for data storage (of course there is better ways to store information, but they are not as pretty :) )

I was thinking of printing 9-block data sheets for sending through mail as a way of data transmission.
Thanks for the great idea. I made a Wordpress plugin for Andi's MonsterID (monsters instead of geometric shapes) code if anyone is interested:
http://scott.sherrillmix.com/blog/blogger/wp_monsterid/
I implemented your algorithm from scratch in a C# class that creates bitmaps.

For those interested:
http://www.puls200.de/?p=316
Very interesting concept...and I like my Identicon. Do you have plans to create/invent identicons that represent names, letters, or words? I suppose that would also be called Japanese (Nihongo) but I digress.
You could just create a hash from a name, text and use it as an input value.
Yes, what Daniel said.


DESIGN TIP: MULTIPLE IDENTICON 'CLASSES'

If your use case uses more than one 'class' of identicons within a single page (i.e. wiki page using identicons for names as well as links) then you can help users distinguish different identicon classes by wrapping them with class-specific borders (i.e. circle for people and square for links).

DESIGN TIP: USING IDENTICONS TO REPRESENT TYPE OF INFO

IP identicon uses an identicon to represent an 'instance' of IP address. Identicons can also be used to represent 'class' of some piece of information.
How about a WordPress plugin? I have no clue how to do php, but it would be a really great wp plugin.
Straight port to WordPress plugin would be nice. Only version we have is MonsterID variation.
Richard Mays   at 2007/02/09 02:05:35 AM
I think this is a really cool idea! This icons really do differentiate people well.
cool project
Nice
Marjorie Lipan   at 2007/02/15 01:06:02 PM
I would have commented this on your entry, "Visual Security: 9-block IP Identification," but it is closed.

I just happened across a couple of other uses of the word "Identicon," which you may or may not be aware of.

1. name of a corporation in a James Bond game (?)
See http://en.wikipedia.org/wiki/Agent_Under_Fire_(video_game)

2. used in a song title, "I Am Not A (Voice Activated Child Identicon)"
http://play.rhapsody.com/servotron/noroomforhumans/iamnotavoiceactivatedchildidenticon

3. Ninja word - however if you click on ninjawords and do a search, it thinks you want identical
see http://wordie.org/words/identicon
Marjorie Lipan   at 2007/02/15 10:15:13 PM
Curious that my identicon now is different. Perhaps this is because I use a cell phone to connect. I suppose that as I change locations, the identicons will also change. I am now about 1.5 to 2 miles away from where I was when I sent the previous message.
Marjorie Lipan   at 2007/02/16 01:23:30 AM
Now I am using the same computer and access card, but this time the identicon is different from the one generated in this location previously. The identicon is the same as was generated a short distance from here. I am just experimenting to see what happens.
Marjorie Lipan   at 2007/02/16 01:27:34 AM
Funny, the blue identicon showed above my name, but the green one with a new shape showed up on the comment. Go figure!? So I now have three different identicons!
I have made a trivial modification that gets a string and uses it as a seed for a 32-bit number, which then gets fed to the canvas rendering method :) ... I am gonna try it on the tags on blogger 2.0.

(The code is in the mail, Don).

Marjorie Lipan: I envy your luck ;)
Don, it works on Blogger 2.0. I still have to check why the page gives out scripting errors with IE6.

http://pencilviolence.blogspot.com/
(it's my blogger 2.0 junkyard)

If anyone wants the patch to the label tag mail:
limacat [atmark] gmail [dot] com
Marjorie Lipan   at 2007/02/17 05:25:06 PM
Davide, I am not sure whether it is luck or schizophrenia! Here is another Identicon thanks to Verizon!
Marjorie Lipan   at 2007/02/17 11:43:07 PM
Here is company called Identicon written in a language I do not understand: http://www.identicon.no/

I suspect that "no" is a country, maybe Norway.
Very nice site! Good work.
<a href="http://uk.geocities.com/pre682bi/sm-leather-gay-escorts.htm">sm leather gay escorts</a>
Hi Don,

I was reviewing your identicon code and had a question about something I thought you might be able to resolve.

If you recall, I wrote that at its core, this identicon code is really converting a hash into an image. It could be a hash of *anything* not just an IP Address. http://haacked.com/archive/2007/01/22/Identicons_as_Visual_Fingerprints.aspx

So I'm confused by all the bit manipulation going on in the method:

public static int getIdenticonCode(InetAddress inetAddr)

I'm also confused by the DNS lookup in the method:

public static int getIdenticonCode(String codeParam, String remoteAddr)

I understand what the DNS code is doing. Since the remote address could come in the format:

"ip, internal-ip"

The DNS code makes sure you can extract a valid IP.

But as far as the Identicon renderer is concerned, it shouldn't require obtaining a valid IP. The remote Address reported to the server should be good enough, as long as that remote addr string (whatever form it takes) is relatively consistent for that user.

For example, it seems to me that you could simplify the code alot and replace both of these methods with something like this: (pseudocode)

public static int getIdenticonCode(String codeParam, String remoteAddr) {
int code = 0;
try {
if (codeParam != null) {
code = Integer.parseInt(codeParam);
} else {
code = md5(remoteAddr).hashCode();
}
} catch (Exception e) {
log.error(e);
}
return code;
}

I tested this out (well an equivalent in C#) and the identicons look just fine to me. Is there something that I'm totally missing here?

Thanks!
Phil
Phil, you are not missing much. As you wrote, identicons can be used for non-IP by applying different algorithms and parameters to calculate the 'identicon code'. This is why I put getIdenticonCode function in the utility class. InetAddress version is IP-specific so it should not be used for non-IP address use cases. String-version of the same function is just there as a convenience function which, unfortunately, could confuse the readers. Sorry about that.

You code should work for non-IP use cases. Salt might be necessary for use cases requiring privacy though.
AndCycle   at 2007/05/14 04:39:50 PM
Hi there,
I have just done a direct porting part from your java code to a piece of working php,
Could you be so generous putting it on this blog?
I have tried searching around php ver. and get no result for any source code like yours,
wish you can put it here and let others to have good use of it :)

http://www.andcycle.idv.tw/~andcycle/php/IdenticonRenderer.phpx
this is such a great idea. congrats on coining a term!
Although, some ISPS (eg AOL) use rotating IPs. Would it be a good idea to set a session cookie upon the first assignment of an identicon, then if a request comes in from a different IP than the session-originator, the code can default to the first identicon. It's safe because in order to spoof the identicon, the attacker would still need to have the victim's cookie.
Your Identicon:
Name: * required
Email:
Website URL:
 
Comment:
HTML not supported