Технический форум

Технический форум (http://www.tehnari.ru/)
-   Помощь студентам (http://www.tehnari.ru/f41/)
-   -   Алгоритмы шифрования (http://www.tehnari.ru/f41/t88111/)

Neonn1k 07.05.2013 18:34

Алгоритмы шифрования
 
Есть у кого часть кода/готовая программа из имеющихся алгоритмов шифрования ниже(на любом языке программирования):
1. Алгоритм Grand Cru
2. Hierocrypt L1
3. Hierocrypt 3
4. HPC
5. ICE
6. Iceberg
7. FROG
8. Kasumi
9. Khazad
10. Loki 97
11. Magenta
12. RC2
13. RC5
14. RC6


Имеется часть кода от RC5 но не могу никак скомпилировать.
Цитата:

/* RC5REF.C -- Reference implementation of RC5-32/12/16 in C. */
/* Copyright (C) 1995 RSA Data Security, Inc. */
typedef unsigned long WORD; /* Should be 32-bit = 4 bytes
*/
#define w 32 /* word size in bits */
#define r 12 /* number of rounds */
#define b 16 /* number of bytes in key */
#define c 4 /* number words in key = ceil(8*b/w)*/
#define t 26 /* size of table S = 2*(r+1) words */
WORD S[t]; /* expanded key table */
WORD P = 0xb7e15163, Q = 0x9e3779b9; /* magic constants */
/* Rotation operators. x must be unsigned, to get logical right shift*/
#define ROTL(x,y) (((x)<<(y&(w-1))) | ((x)>>(w-(y&(w-1)))))
#define ROTR(x,y) (((x)>>(y&(w-1))) | ((x)<<(w-(y&(w-1)))))

void RC5_ENCRYPT(WORD *pt, WORD *ct) /* 2 WORD input pt/output ct */
{ WORD i, A=pt[0]+S[0], B=pt[1]+S[1];
for (i=1; i<=r; i++)
{ A = ROTL(A^B,B)+S[2*i];
B = ROTL(B^A,A)+S[2*i+1];
}
ct[0] = A; ct[1] = B;
}

void RC5_DECRYPT(WORD *ct, WORD *pt) /* 2 WORD input ct/output pt */
{ WORD i, B=ct[1], A=ct[0];
for (i=r; i>0; i--)
{ B = ROTR(B-S[2*i+1],A)^A;
A = ROTR(A-S[2*i],B)^B;
}
pt[1] = B-S[1]; pt[0] = A-S[0];
}

void RC5_SETUP(unsigned char *K) /* secret input key K[0...b-1] */
{ WORD i, j, k, u=w/8, A, B, L[c];
/* Initialize L, then S, then mix key into S */
for (i=b-1,L[c-1]=0; i!=-1; i--) L[i/u] = (L[i/u]<<8)+K[i];
for (S[0]=P,i=1; i<t; i++) S[i] = S[i-1]+Q;
for (A=B=i=j=k=0; k<3*t; k++,i=(i+1)%t,j=(j+1)%c) /* 3*t > 3*c */
{ A = S[i] = ROTL(S[i]+(A+B),3);
B = L[j] = ROTL(L[j]+(A+B),(A+B));
}
}

Neonn1k 07.05.2013 23:05

Алгоритм TwoFish
C# implementation of the Twofish cipher.
Цитата:

public sealed class Twofish: SymmetricAlgorithm {
public Twofish() {
this.LegalKeySizesValue = new KeySizes[] {
new KeySizes(128, 256, 64)
};
this.LegalBlockSizesValue = new KeySizes[] {
new KeySizes(128, 128, 0)
};
this.BlockSize = 128;
this.KeySize = 128;
this.Padding = PaddingMode.Zeros;
this.Mode = CipherMode.ECB;

}

public override ICryptoTransform CreateEncryptor(byte[] key, byte[] iv) {
Key = key;

if (Mode == CipherMode.CBC) IV = iv;

return new TwofishEncryption(KeySize, ref KeyValue, ref IVValue, ModeValue, TwofishBase.EncryptionDirection.Encrypting);
}

public override ICryptoTransform CreateDecryptor(byte[] key, byte[] iv) {
Key = key;

if (Mode == CipherMode.CBC) IV = iv;

return new TwofishEncryption(KeySize, ref KeyValue, ref IVValue, ModeValue, TwofishBase.EncryptionDirection.Decrypting);
}

public override void GenerateIV() {
IV = new byte[16] {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
}

public override void GenerateKey() {
Key = new byte[KeySize / 8];

for (int i = Key.GetLowerBound(0); i < Key.GetUpperBound(0); i++) {
Key[i] = 0;
}
}

public override CipherMode Mode {
set {
switch (value) {
case CipherMode.CBC:
break;
case CipherMode.ECB:
break;
default:
throw (new CryptographicException("Not supported."));
}
this.ModeValue = value;
}
}
}

Выдаёт кучу ошибок. Посмотрите пожалуйста. Если заработает киньте готовую программу, а то завтра уже зачёт(


Часовой пояс GMT +4, время: 00:31.

Powered by vBulletin® Version 4.5.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.