Secure Hash Algorithm 1
SHA1 in C#, Java, PHP, Perl, and Python
PHP wins.
It’s just data
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()
__import__('sha').new("It's just data").hexdigest()
Posted by Mark atPerl 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")
To me it looks like PHP loses :)
Seriously, having everything in core without modules is just scary.
Posted by Gavin atFor 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 atGavin,
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.
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 atSam'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 atThe 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 atHere it is in MySQL:
mysql> SELECT SHA1("It's just data");
Posted by John Beimler at[@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<a href='http://www.intertwingly.net/blog/1545.html' >SHA1 in various languages</a>...
[more]
Trackback from 2lmc spool
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 atSam Ruby: Secure Hash Algorithm 1SHA1 in C#, Java, PHP, Perl, and Python Sam says : "PHP wins." He has......
[more]
Trackback from Raw Blog
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 atThanks 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
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 atRecently 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 atRecently 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 atYou 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 atI 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 atSHA1 in C#, Java, PHP, Perl, and Python...
Excerpt from del.icio.us/alan.dean/sha atIn 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[link]...
Excerpt from Delicious/crazycao/sha1 atI 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 atIt 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...voyance par telephone
Posted by seo atpleasant post, stay aware of this fascinating work. It truly regards realize that this subject is being secured likewise on this site so cheers for setting aside time to talk about this! seorango
Posted by SEOPAK at