FileDocCategorySizeDatePackage
otp.javaAPI DocExample20769Sun Dec 27 14:20:54 GMT 1998None

otp

public class otp extends Object

Fields Summary
int
seq
String
seed
String
passphrase
byte[]
hash
int
sha
static final byte
MD4
static final byte
MD5
static String[]
words
Constructors Summary
otp(int n, String s, String p, int hashalg)


            
	this.seq = n;
	this.seed = s;
	this.passphrase = p;
	this.sha = hashalg;
    
Methods Summary
public static java.lang.Stringbtoe(int index)

        if (index < words.length) {
    	    return words[index];
        } else {
           return "bogus";
        }
    
voidcalc()

	if (this.sha == MD5) {
	    this.md5calc();
	} else {
	    this.md4calc();
        }
    
voidmd4calc()

	int tmpseq = this.seq;
	md4 mdc;

	mdc = new md4(this.seed + this.passphrase);
	mdc.calc();
	this.hash = otpfoldregs(mdc.getregs());
	while (tmpseq > 0) {
	    mdc = new md4(hash);
	    mdc.calc();
	    this.hash = otpfoldregs(mdc.getregs());
	    tmpseq--;
	}
    
voidmd5calc()

	int tmpseq = this.seq;
	md5 mdc;

	mdc = new md5(this.seed + this.passphrase);
	mdc.calc();
	this.hash = otpfoldregs(mdc.getregs());
	while (tmpseq > 0) {
	    mdc = new md5(hash);
	    mdc.calc();
	    this.hash = otpfoldregs(mdc.getregs());
	    tmpseq--;
	}
    
static byte[]otpfoldregs(int[] regs)

	int ac, bd, i;
	byte fold[] = new byte[8];

	ac = regs[0] ^ regs[2];
	bd = regs[1] ^ regs[3];
	for (i=0; i < 4; i++) {
	    fold[i] = (byte) (ac & 0xff);
	    ac >>= 8;
	}
	for (i=4; i < 8; i++) {
	    fold[i] = (byte) (bd & 0xff);
	    bd >>= 8;
	}
	return fold;
    
public java.lang.StringtoString()

	long wi, tmplong;
	String tmpstr;
	int i, j;
	byte parity;

	wi = this.tolong();
	tmplong = wi;
	tmpstr = "";
	parity = 0;
	for (i = 0; i < 64; i+=2) {
	    parity += tmplong & 0x3;
	    tmplong >>= 2;
	}
	for (i=4; i >= 0; i--) {
	    tmpstr += btoe((int) 
		      ((wi >> (i * 11 + 9)) & 0x7ff)) + " ";
	}
	tmpstr += btoe((int) ((wi << 2) & 0x7fc) | (parity & 0x03));
	return tmpstr;
    
longtolong()

	long wi;
	int i;

	wi = 0;
	for (i=0; i < 8; i++) {
	    wi <<= 8;
	    wi |= (this.hash[i] & 0xff);
	}
	return wi;