:: Úvod

:: Tím

:: Projekt

:: Prezentácia

:: Stav projektu

:: Dokumentácia

:: Odkazy

     Algoritmy


Úvod do prezentácie
História šifry
Opis šifry
Šifrovanie
Dešifrovanie
Kryptoanalýza

Interaktívna
prezentácia

Algoritmy


Násobenie 216 + 1

Opis v C:

uint16 mulmo(uint16 x, uint16 y)
{
uint32 t;
x = (x - 1) & 0xFFFF;
y = (y - 1) & 0xFFFF;
t = (uint32) x * y + x + y + 1;
x = t & 0xFFFF;
y = t >> 16;
x = (x - y) + (x <= y);
return x;
}

Opis vo VHDL:

ENTITY MUL16 IS
PORT(
CLK : IN STD_LOGIC;
X : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
Y : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
W : OUT STD_LOGIC_VECTOR (15 DOWNTO 0)
);
END MUL16 ;

ARCHITECTURE MUL16 OF MUL16 IS
SIGNAL P : STD_LOGIC_VECTOR (35 DOWNTO 0);
SIGNAL A,B,C : STD_LOGIC_VECTOR (17 DOWNTO 0);
BEGIN
PROCESS(CLK)
BEGIN
IF (CLK = '1'AND CLK'EVENT) THEN
A(17 DOWNTO 16) <= "00";
B(17 DOWNTO 16) <= "00";
C(17 DOWNTO 16) <= "00";
A(15 DOWNTO 0) <= (X-1);
B(15 DOWNTO 0) <= (Y-1);
P <= (A*B) + (A + B + 1);
C(15 DOWNTO 0) <= P(15 DOWNTO 0);
IF(C(16 DOWNTO 0) > P(32 DOWNTO 16))THEN
W <= (P(15 DOWNTO 0) - P(31 DOWNTO 16));
ELSE
W <= (P(15 DOWNTO 0) - P(31 DOWNTO 16)) + 1;
END IF;
END IF;
END PROCESS;
END MUL16;

Sčítanie mod 216

Opis v C:

uint16 add16(uint16 x, uint16 y)
{
uint32 t;
t = (uint32) x + y;
return (t & 0xFFFF);
}


Opis vo VHDL:

ENTITY ADD16_2 IS
PORT(
CLK : IN STD_LOGIC;
X : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
Y : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
W : OUT STD_LOGIC_VECTOR (15 DOWNTO 0)
);
END ADD16_2 ;

ARCHITECTURE ADD16_2 OF ADD16_2 IS
BEGIN
PROCESS(CLK)
BEGIN
IF (CLK = '1'AND CLK'EVENT) THEN
W <= X + Y;
END IF;
END PROCESS;
END ADD16_2;

XOR

Opis vo VHDL:

ENTITY XOR16X16 IS
PORT(
CLK : IN STD_LOGIC;
X : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
Y : IN STD_LOGIC_VECTOR (15 DOWNTO 0);
W : OUT STD_LOGIC_VECTOR (15 DOWNTO 0)
);
END XOR16X16 ;

ARCHITECTURE XOR16 OF XOR16X16 IS
BEGIN
PROCESS(CLK)
BEGIN
IF (CLK = '1'AND CLK'EVENT) THEN
W <= X XOR Y;
END IF;
END PROCESS;
END XOR16;

Inverzné sčítanie (mod 216)

Opis v Java:

int iadd(int b) {
return (65536 - b) & 0xFFFF;
}

Inverzné násobenie (mod 216 +1)

Opis v Java:

int fun2(int b) {
int a=65537;
int d, q, r, x, y, x1, x2, y1, y2;

if (b==0) return(0);
x2=1; x1=0; y2=0; y1=1;
while (b>0) {
q=a/b;
r=a-q*b;
x=x2-q*x1;
y=y2-q*y1;
a=b; b=r; x2=x1; x1=x; y2=y1; y1=y;
}
if (y2<0) y2=65537+y2;
y2 = y2 & 0xFFFF;
return(y2);
}

 

naspäť hore