ouahed
2017-04-12, 22:35
ممكن مساعدة في هدا الكود يقول بأن main غير موجود
package implementation1;
public class streamc {// use for Encryption
public static int R1,R2,R3;
/* Masks for the three shift registers */
static int R1MASK = 524287; /* 19 bits, numbered 0..18 */
static int R2MASK = 4194303; /* 22 bits, numbered 0..21 */
static int R3MASK = 8388607; /* 23 bits, numbered 0..22 */
/* Middle bit of each of the three shift registers, for clock control */
static int R1MID = 256; /* bit 8 */
static int R2MID = 1024; /* bit 10 */
static int R3MID = 1024; /* bit 10 */
/* Feedback taps, for clocking the shift registers.
* These correspond to the primitive polynomials
* x^19 + x^5 + x^2 + x + 1, x^22 + x + 1,
* and x^23 + x^15 + x^2 + x + 1. */
static int R1TAPS = 466944; /* bits 18,17,16,13 */
static int R2TAPS = 3145728; /* bits 21,20 */
static int R3TAPS = 7340160; /* bits 22,21,20,7 */
/* Output taps, for output generation */
static int R1OUT = 262144; /* bit 18 (the high bit) */
static int R2OUT = 2097152; /* bit 21 (the high bit) */
static int R3OUT = 4194304; /* bit 22 (the high bit) */
public static int parity(int x) {
x ^= x>>>16;
x ^= x>>>8;
x ^= x>>>4;
x ^= x>>>2;
x ^= x>>>1;
x = x & 1;
return x ;
}
public static int clockone(int reg, int mask, int taps) {
int t = reg & taps;
reg = (reg << 1) & mask;
reg |= parity(t);
return reg;
}
public static boolean majority() {
int sum;
sum = parity(R1&R1MID) + parity(R2&R2MID) + parity(R3&R3MID);
if (sum >= 2)
return true;
else
return false;
}
public static void clock() {
boolean maj = majority();
if (((R1&R1MID)!=0) == maj)
R1 = clockone(R1, R1MASK, R1TAPS);
if (((R2&R2MID)!=0) == maj)
R2 = clockone(R2, R2MASK, R2TAPS);
if (((R3&R3MID)!=0) == maj)
R3 = clockone(R3, R3MASK, R3TAPS);
}
public static void clockallthree() {
R1 = clockone(R1, R1MASK, R1TAPS);
R2 = clockone(R2, R2MASK, R2TAPS);
R3 = clockone(R3, R3MASK, R3TAPS);
}
public static int getbit() {
return parity(R1&R1OUT)^parity(R2&R2OUT)^parity(R3&R3OUT);
}
public static void keysetup(byte key[], int frame) {
int i;
int keybit, framebit;
/* Zero out the shift registers. */
R1=0; R2=0; R3 = 0;
/* Load the key into the shift registers,
* LSB of first byte of key array first,
* clocking each register once for every
* key bit loaded. (The usual clock
* control rule is temporarily disabled.) */
for (i=0; i<64; i++) {
clockallthree(); /* always clock */
keybit = (int)((key[i/8] >> (i&7))) & 1; /* The i-th bit of the key */
R1 ^= keybit; R2 ^= keybit; R3 ^= keybit;
}
/* Load the frame number into the shift
* registers, LSB first,
* clocking each register once for every
* key bit loaded. (The usual clock
* control rule is still disabled.) */
for (i=0; i<22; i++) {
clockallthree(); /* always clock */ framebit = (frame >> i) & 1; /* The i-th bit of the frame # */ R1 ^= framebit; R2 ^= framebit; R3 ^= framebit; }
/* Run the shift registers for 100 clocks
* to mix the keying material and frame number * together with output generation disabled,
* so that there is sufficient avalanche.
* We re-enable the majority-based clock control
* rule from now on. */ for (i=0; i<100; i++) { clock(); }
/* Now the key is properly set up. */
}
public static void run(int AtoBkeystream[], int BtoAkeystream[]) { int i;
/* Zero out the output buffers. */ for (i=0; i<=113/32; i++) { AtoBkeystream[i] = 0; BtoAkeystream[i] = 0; }
/* Generate 114 bits of keystream for the
* A->B direction. Store it, MSB first. */ for (i=0; i<114; i++) { clock(); AtoBkeystream[i/32] |= getbit() << (31-(i&31));}
/* Generate 114 bits of keystream for the
* B->A direction. Store it, MSB first. */ for (i=0; i<114; i++) { clock(); BtoAkeystream[i/32] |= getbit() << (31-(i&31));
}}
public streamc (byte[] key, int frame, int AtoBkeystream[], int BtoAkeystream[]) {
keysetup (key,frame); run (AtoBkeystream, BtoAkeystream); }
}
package implementation1;
public class streamc {// use for Encryption
public static int R1,R2,R3;
/* Masks for the three shift registers */
static int R1MASK = 524287; /* 19 bits, numbered 0..18 */
static int R2MASK = 4194303; /* 22 bits, numbered 0..21 */
static int R3MASK = 8388607; /* 23 bits, numbered 0..22 */
/* Middle bit of each of the three shift registers, for clock control */
static int R1MID = 256; /* bit 8 */
static int R2MID = 1024; /* bit 10 */
static int R3MID = 1024; /* bit 10 */
/* Feedback taps, for clocking the shift registers.
* These correspond to the primitive polynomials
* x^19 + x^5 + x^2 + x + 1, x^22 + x + 1,
* and x^23 + x^15 + x^2 + x + 1. */
static int R1TAPS = 466944; /* bits 18,17,16,13 */
static int R2TAPS = 3145728; /* bits 21,20 */
static int R3TAPS = 7340160; /* bits 22,21,20,7 */
/* Output taps, for output generation */
static int R1OUT = 262144; /* bit 18 (the high bit) */
static int R2OUT = 2097152; /* bit 21 (the high bit) */
static int R3OUT = 4194304; /* bit 22 (the high bit) */
public static int parity(int x) {
x ^= x>>>16;
x ^= x>>>8;
x ^= x>>>4;
x ^= x>>>2;
x ^= x>>>1;
x = x & 1;
return x ;
}
public static int clockone(int reg, int mask, int taps) {
int t = reg & taps;
reg = (reg << 1) & mask;
reg |= parity(t);
return reg;
}
public static boolean majority() {
int sum;
sum = parity(R1&R1MID) + parity(R2&R2MID) + parity(R3&R3MID);
if (sum >= 2)
return true;
else
return false;
}
public static void clock() {
boolean maj = majority();
if (((R1&R1MID)!=0) == maj)
R1 = clockone(R1, R1MASK, R1TAPS);
if (((R2&R2MID)!=0) == maj)
R2 = clockone(R2, R2MASK, R2TAPS);
if (((R3&R3MID)!=0) == maj)
R3 = clockone(R3, R3MASK, R3TAPS);
}
public static void clockallthree() {
R1 = clockone(R1, R1MASK, R1TAPS);
R2 = clockone(R2, R2MASK, R2TAPS);
R3 = clockone(R3, R3MASK, R3TAPS);
}
public static int getbit() {
return parity(R1&R1OUT)^parity(R2&R2OUT)^parity(R3&R3OUT);
}
public static void keysetup(byte key[], int frame) {
int i;
int keybit, framebit;
/* Zero out the shift registers. */
R1=0; R2=0; R3 = 0;
/* Load the key into the shift registers,
* LSB of first byte of key array first,
* clocking each register once for every
* key bit loaded. (The usual clock
* control rule is temporarily disabled.) */
for (i=0; i<64; i++) {
clockallthree(); /* always clock */
keybit = (int)((key[i/8] >> (i&7))) & 1; /* The i-th bit of the key */
R1 ^= keybit; R2 ^= keybit; R3 ^= keybit;
}
/* Load the frame number into the shift
* registers, LSB first,
* clocking each register once for every
* key bit loaded. (The usual clock
* control rule is still disabled.) */
for (i=0; i<22; i++) {
clockallthree(); /* always clock */ framebit = (frame >> i) & 1; /* The i-th bit of the frame # */ R1 ^= framebit; R2 ^= framebit; R3 ^= framebit; }
/* Run the shift registers for 100 clocks
* to mix the keying material and frame number * together with output generation disabled,
* so that there is sufficient avalanche.
* We re-enable the majority-based clock control
* rule from now on. */ for (i=0; i<100; i++) { clock(); }
/* Now the key is properly set up. */
}
public static void run(int AtoBkeystream[], int BtoAkeystream[]) { int i;
/* Zero out the output buffers. */ for (i=0; i<=113/32; i++) { AtoBkeystream[i] = 0; BtoAkeystream[i] = 0; }
/* Generate 114 bits of keystream for the
* A->B direction. Store it, MSB first. */ for (i=0; i<114; i++) { clock(); AtoBkeystream[i/32] |= getbit() << (31-(i&31));}
/* Generate 114 bits of keystream for the
* B->A direction. Store it, MSB first. */ for (i=0; i<114; i++) { clock(); BtoAkeystream[i/32] |= getbit() << (31-(i&31));
}}
public streamc (byte[] key, int frame, int AtoBkeystream[], int BtoAkeystream[]) {
keysetup (key,frame); run (AtoBkeystream, BtoAkeystream); }
}