It’s just data

Secure Hash Algorithm 1

SHA1 in C#, Java, PHP, Perl, and Python

PHP wins.


Agreed, though the Python could come closer.

import sha
print sha.new("It's just data").hexdigest()

Posted by joe at

__import__('sha').new("It's just data").hexdigest()

Posted by Mark at

Perl version using Joe's chaining above:
use Digest::SHA1;
print Digest::SHA1->new->add("It's just data")->hexdigest;

Or do it in functional style:
use Digest::SHA1 'sha1_hex';
print sha1_hex "It's just data";

And here it is in Ruby:
require 'digest/sha1'
print Digest::SHA1.hexdigest("It's just data")

Posted by Arien at

To me it looks like PHP loses :)

Seriously, having everything in core without modules is just scary.

Posted by Gavin at

For Javascript...

Leigh Dodd's FOAF-a-matic tool uses a sha1.js library, see...

http://www.ldodds.com/foaf/foaf-a-matic.html
http://www.ldodds.com/foaf/js/sha1.js

http://pajhome.org.uk/crypt/md5/sha1src.html

function sha1_vm_test()
{
  return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
}

ps. thanks for the other references, I'll link it from the FOAF spec.

Posted by Dan Brickley at

Gavin,
It is modular, it's just that the modules all share the same flat
namespace and are included when the interpreter is compiled rather
than at runtime.

It's still pretty ugly, but it's designed for people who want to hack
out something quick and dirty. There are ways of cleaning PHP up
a bit if that's what you want to do, although if you're going to
try you might as well just use something else.

Posted by Martin Atkins at

OK, I've wrapped the javascript into html and added it to the directory.  As well as adding the Ruby example.

Each has been verified to produce the same result.

Thanks!

Posted by Sam Ruby at

C# SHA1 String Hashing

Sam's C# version could be marginally abbreviated (and much less legible). Which is virtually useless, although I would hope no one is writing one-time string hashing routines. I'm sure it could probably be compressed further, but you have to give it...

Excerpt from xL8 - Grant Carpenter at

The Java version could be slightly improved:

  md.update(data.getBytes());
  byte[] digest = md.digest();

can be wrapped into:

  byte[] digest = md.digest(data.getBytes());

... and the byte[] to hex loop could be modified to avoid the unnecessary string concatenation:

  for(int i=0; i<digest.length; i++) {
  int digByte = digest[i]&0xFF;
  if(digByte<0x10) System.out.print('0');
  System.out.print(Integer.toHexString(digByte));
  }

Of course, these changes are pretty trivial.  And I'm not trying to turn this into the International Obfuscated Code Contest ;)

Posted by Jason Brome at

Here it is in MySQL:

mysql> SELECT SHA1("It's just data");

Posted by John Beimler at

Yabadabadoo

[@065] YourKit Memory Profiler 1.0 released. JSP deployments rapidly growing. 94% increase in JSP deployments since July 2002. Red Hat Linux 9 and Java 2 Platform, Standard Edition 1.4.2: A Winning Combination. Matt — Apache J2EE Project and...

Excerpt from Erik's Weblog at

2003/08/06 14:11

<a href='http://www.intertwingly.net/blog/1545.html' >SHA1 in various languages</a>... [more]

Trackback from 2lmc spool

at

Gavin wrote:

To me it looks like PHP loses :)
Seriously, having everything in core without
modules is just scary.

PHP does not have sha1() in its core, but in its ext/standard module. Whether or not you want to build your PHP with the standard module is another story, but the SHA1 code is not in PHP's core, the Zend Engine.

Posted by Sebastian Bergmann at

SHA1 in code

Sam Ruby: Secure Hash Algorithm 1SHA1 in C#, Java, PHP, Perl, and Python Sam says : "PHP wins." He has...... [more]

Trackback from Raw Blog

at

Above the trophy case hangs an elvish sword of great antiquity.

I will run out of Zork quotes eventually. Also, I need to stop skipping a day between reading NetNewsWire posts... I dread to think of how many I'll have to read after vacation next week (and, given my average of ~60 email a day, how much email I'll...

Excerpt from Among Other Things at

SHA1

Thanks to John Wiseman, and of course Nathan Froyd, I can now provide the winning answer (provided that parenthesis count is the criteria): (require :sha1) (map 'vector #'(lambda (x) (format t "~16R" x)) (SHA:sha1sum-sequence "It's just data")) That ...

Pingback from Gordon Weakliem's Weblog

at

Congradulations. You've demostrated that PHP is the best language for writing a one line program which outputs an sha1 hash of a trivial string.

I don't think there's any disputing it.

Posted by David Jeske at

Transforming <foaf:mbox> to <foaf:mbox_sha1sum>

Recently I added a number of people into my FOAF file. At first I included their email addresses in plaintext using the <foaf:mbox> property, but I decided that this wasn't really acceptable for several reasons so decided to switch to using...

Excerpt from Random and Irrelevant at

Transforming <foaf:mbox> to <foaf:mbox_sha1sum>

Recently I added a number of people into my FOAF file. At first I included their email addresses in plaintext using the <foaf:mbox> property, but I decided that this wasn't really acceptable for several reasons so decided to switch to using...

Excerpt from Random and Irrelevant at

You guys obvious have animosity towards php. Most likely because someone took your job, or brags about it a lot. Regardless your reasons for hating the most popular scripting language are unwarranted and purely immature.

Posted by PHPGURU at

I have put a little Java Applet up that does sha1sum testing.
My Bloomin Friends

There is a link from there to the source code.

Posted by Henry Story at

Sam Ruby: Secure Hash Algorithm 1

SHA1 in C#, Java, PHP, Perl, and Python...

Excerpt from del.icio.us/alan.dean/sha at

In the war of language no one can’t say who will win. But still one win in some cases in other wins in other case. Here PHP won. JAVA is the most suitable one to use but PHP has many advantages. So it won here. What u say??Am i wrong??

Posted by Rohit K at

Sam Ruby: Secure Hash Algorithm 1

[link]...

Excerpt from Delicious/crazycao/sha1 at

Code-Decode - SHA1

I recently had to implement a hashing algorithm that will be used as a key in seperate repositories. It wasn’t too hard to pick SHA1 out of the many different types. When implementing any encryption, it’s important to make sure the algorithm works...

Excerpt from I <3 Work at

Add your comment