aspose file tools*
The moose likes Beginning Java and the fly likes Give me plz a help I NEED THAT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Give me plz a help I NEED THAT" Watch "Give me plz a help I NEED THAT" New topic

Give me plz a help I NEED THAT

Mohammad Ahmad

Joined: Mar 21, 2006
Posts: 18
Hi plz i need to implement Sha1 in java and i tooked a good look on Security.MessageDigest in java packages...but i need to implement it from scratch ..i have a big problem in making the append operation using the shift bitwise so plz any one can help me on how to make the append operation for the 1 and the zeros bits??
i had this code from some place but also i couldnt understand it well so if any can help me on:

public class SHA1 {

* Bitwise rotate a 32-bit number to the left
private static int rol(int num, int cnt) {
return (num << cnt) | (num >>> (32 - cnt));

* Take a string and return the base64 representation of its SHA-1.
public static String encode(String str) {

// Convert a string to a sequence of 16-word blocks, stored as an array.
// Append padding bits and the length, as described in the SHA1 standard

byte[] x = str.getBytes();
int[] blks = new int[(((x.length + 8) >> 6) + 1) * 16];
int i;

for(i = 0; i < x.length; i++) {
blks[i >> 2] |= x[i] << (24 - (i % 4) * 8);

blks[i >> 2] |= 0x80 << (24 - (i % 4) * 8);
blks[blks.length - 1] = x.length * 8;

plz iam waiting the reply my message must be stored in a file then i have to calculate the Message Digest...
Joe Ess

Joined: Oct 29, 2001
Posts: 8927

Forgive me for being dense, but I read your previous post and I can't figure out why you are trying to reimplement SHA when it is available in the API. Perhaps if you would elaborate on your requirement we could give you better advice.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
It is sorta covered in the JavaRanch Style Guide.
subject: Give me plz a help I NEED THAT