FileDocCategorySizeDatePackage
Sha1AlgorithmHelper.javaAPI DocAzureus 3.0.3.45320Sat Mar 13 14:46:22 GMT 2004org.gudy.azureus2.core3.util.test

Sha1AlgorithmHelper

public class Sha1AlgorithmHelper extends Object
author
Olivier

Fields Summary
Constructors Summary
Methods Summary
public static voidalgorithm2()

    int mask = 0x0000000F;
  	for(int t = 0 ; t <= 79 ; t++) {
  		int s = t & mask;
      if(t >= 16) {
        System.out.println("w" + s + " = w" + ((s+13) & mask) + " ^ w" + ((s+8) & mask) + " ^ w" + ((s+2) & mask) + " ^ w" + s + "; w" + s + " = (w" + s + " << 1) | (w" + s + " >>> 31) ;");        
      }
      System.out.print("temp = ((a << 5) | (a >>> 27)) + e + w" + s + " + ");
      int ft = t / 20;
      if(ft == 0) {
        System.out.println("((b & c) | ((~b) & d)) + 0x5A827999 ;");
      }
      if(ft == 1) {
        System.out.println("(b ^ c ^ d) + 0x6ED9EBA1 ;");
      }
      if(ft == 2) {
        System.out.println("((b & c) | (b & d) | (c & d)) + 0x8F1BBCDC ;");
      }
      if(ft == 3) {
        System.out.println("(b ^ c ^ d) + 0xCA62C1D6 ;");
      }
      System.out.println("e=d ; d=c ; c = (b << 30) | (b >>> 2) ; b=a ; a=temp;");
  	}
  
public static voidalgorithm2NoShift()

    String variables = "abcde";
    int mask = 0x0000000F;
    for(int t = 0 ; t <= 79 ; t++) {
      String a = "" + variables.charAt((85-t)%5);
      String b = "" + variables.charAt((85-t+1)%5);
      String c = "" + variables.charAt((85-t+2)%5);
      String d = "" + variables.charAt((85-t+3)%5);
      String e = "" + variables.charAt((85-t+4)%5);
      
      int s = t & mask;
      if(t >= 16) {
        System.out.println("w" + s + " = w" + ((s+13) & mask) + " ^ w" + ((s+8) & mask) + " ^ w" + ((s+2) & mask) + " ^ w" + s + "; w" + s + " = (w" + s + " << 1) | (w" + s + " >>> 31) ;");        
      }
      System.out.print(e + " += ((" + a + " << 5) | ( " + a + " >>> 27)) + w" + s + " + ");
      int ft = t / 20;
      if(ft == 0) {
        System.out.println("((" + b +" & " + c + ") | ((~" + b +" ) & " + d + ")) + 0x5A827999 ;");
      }
      if(ft == 1) {
        System.out.println("(" + b +" ^ " + c + " ^ " + d + ") + 0x6ED9EBA1 ;");
      }
      if(ft == 2) {
        System.out.println("((" + b +" & " + c + ") | (" + b + " & " + d + ") | (" + c + " & " + d + ")) + 0x8F1BBCDC ;");
      }
      if(ft == 3) {
        System.out.println("(" + b + " ^ " + c + " ^ " + d + ") + 0xCA62C1D6 ;");
      }
      System.out.println(b + " = (" + b + " << 30) | (" + b + " >>> 2) ;");
    }
  
public static voidmain(java.lang.String[] args)

    algorithm2NoShift();
  
public static voidpart1()

    for(int t = 16 ; t <= 79 ; t++) {
    	System.out.println( "w" + t + " = w" + (t-3) + " ^ w" + (t-8) + " ^ w" + (t-14) + " ^ w" + (t-16) + ";");
    	System.out.println( "w" + t + " = (w" + t + " << 1) | (w" + t + " >>> 31);");
    }
  
public static voidpart2()

  	for(int t=0; t<= 79 ; t++) {
      int fn = t / 20;      
      System.out.print("temp = ((a << 5) | (a >>> 27)) + e + w" + t + " + ");
      if(fn == 0) {
        System.out.println("((b & c) | ((~b) & d)) + 0x5A827999 ;");
      }
      if(fn == 1) {
        System.out.println("(b ^ c ^ d) + 0x6ED9EBA1 ;");
      }
      if(fn == 2) {
        System.out.println("((b & c) | (b & d) | (c & d)) + 0x8F1BBCDC ;");
      }
      if(fn == 3) {
        System.out.println("(b ^ c ^ d) + 0xCA62C1D6 ;");
      }
      System.out.println("e = d ; d = c ; c = (b<<30) | (b >>> 2); b = a; a = temp;");
  	}