文章目录:
- 1、用VB编写好的文件的加密与解密软件,谢谢各位大侠!最好是有源代码.谢谢!
- 2、高分急求AES源代码
- 3、求AES加密算法 C代码
- 4、VB 高手来看看 求解 百度上的,VB AES加密模块和代码是真的吗。是否可靠呀,算法都公布了,那
用VB编写好的文件的加密与解密软件,谢谢各位大侠!最好是有源代码.谢谢!
Option Explicit
Dim i As Long
Dim databuff() As Byte ’定义数组用于存放文件内容
Dim addbuff() As Byte ’定义数组用于存放加密后的文件内容
Dim password() As Byte ’定义数组用于存放密码的ASCII值
Dim filename As String
Private Sub Check1_Click()�
If Check1.Value Then ’控制是否显示全部文件
File1.Pattern = "*.*"
Else
File1.Pattern = ".txt"
End If
End Sub
Private Sub Command1_Click()�
Dim j As Integer
Dim password_len As Integer
password_len = Len(Text2.Text)
ReDim password(password_len) As Byte
For i = 0 To password_len - 1 ’把密码转化为ASCII码
password(i)= Asc(Mid(Text2.Text,i + 1,1))
Next
If filename = "" Then Exit Sub
Open filename For Binary As #1 ’读取要加密的文件内容
ReDim databuff(LOF(1))
Get #1,, databuff
Close #1
ReDim addbuff(UBound(databuff))As Byte
For i = 0 To UBound(databuff)
If j = password_len Then ’循环使用密码
j = 0
Else
j = j + 1
End If
addbuff(i)= databuff(i)Xor password(j)’进行异或运算
Next
Open filename For Binary As #1 ’把加密后的内容写入文件
Put #1,,addbuff
Close #1
Text1 = StrConv(addbuff vbUnicode)’显示加密后的文件内容
Text2.Text = ""
End Sub
Private Sub Command2_Click()�
.End
End Sub
Private Sub Dir1_Change()�
File1.Path = Dir1.Path ’与文件列表框相关联
End Sub
Private Sub Drive1_Change()�
On Error GoTo a0
Dir1.Path = Drive1.Drive ’与目录列表框相关联
a0:If Err Then MsgBox(Error(Err))’发生错误,提示错误内容
End Sub
Private Sub File1_Click()’单击文件时,显示文件内容
filename = Dir1.Path + File1.filename
If filename = "" Then Exit Sub
Open filename For Binary As #1
ReDim databuff(LOF(1))
Get #1,,databuff
Close #1
Text1 = StrConv(databuff,vbUnicode)
End Sub
高分急求AES源代码
#define decrypt TRUE
#define encrypt FALSE
#define TYPE BOOL
typedef struct _AES{
int Nb;
int Nr;
int Nk;
unsigned long *Word;
unsigned long *State;
}AES;
/*
加密数据
byte *input 明文
byte *inSize 明文长
byte *out 密文存放的地方
byte *key 密钥key
byte *keySize 密钥长
*/
void Cipher(
unsigned char* input,
int inSize,
unsigned char* out,
unsigned char* key,
int keySize);
/*
解密数据
byte *input 密文
int *inSize 密文长
byte *out 明文存放的地方
byte *key 密钥key
int *keySize 密钥长
*/
void InvCipher(
unsigned char* input,
int inSize,
unsigned char* out,
unsigned char* key,
int keySize);
/*
生成加密用的参数AES结构
int inSize 块大小
byte* 密钥
int 密钥长
unsigned long 属性(标实类型)
返回AES结构指针
*/
AES *InitAES(AES *aes,
int inSize,
unsigned char* key,
int keySize, TYPE type);
/*
生成加密用的参数AES结构
int inSize 块大小
byte* 密钥
int 密钥长
返回AES结构指针
*/
AES *InitAES(
int inSize,
unsigned char* key,
int keySize, BOOL );
/*
加密时进行Nr轮运算
AES * aes 运行时参数
*/
void CipherLoop(
AES *aes);
/*
解密时进行Nr轮逆运算
AES * aes 运行时参数
*/
void InvCipherLoop(
AES *aes);
/*
释放AES结构和State和密钥库word
*/
void freeAES(
AES *aes);
//AES.cpp
#include "stdafx.h"
#include
#include
#include "AES.h"
unsigned char* SubWord(unsigned char* word);
unsigned long* keyExpansion(unsigned char* key, int Nk, int Nr,int);
/*
加密数据
byte *input 明文
byte *inSize 明文长
byte *out 密文存放的地方
byte *key 密钥key
byte *keySize 密钥长
*/
void Cipher(unsigned char* input, int inSize, unsigned char* out, unsigned char* key, int keySize)
{
AES aes ;
InitAES(aes,inSize,key,keySize,encrypt);
memcpy(aes.State,input,inSize);
CipherLoop(aes);
memcpy(out,aes.State,inSize);
}
/*
解密数据
byte *input 密文
int *inSize 密文长
byte *out 明文存放的地方
byte *key 密钥key
int *keySize 密钥长
*/
void InvCipher(unsigned char* input, int inSize, unsigned char* out, unsigned char* key, int keySize)
{
AES aes;
InitAES(aes,inSize,key,keySize,decrypt);
memcpy(aes.State,input,inSize);
InvCipherLoop(aes);
memcpy(aes.State,out,inSize);
}
/*
生成加密用的参数AES结构
int inSize 块大小
byte* 密钥
int 密钥长
返回AES结构指针
*/
AES *InitAES(AES *aes,int inSize, unsigned char *key, int keySize, TYPE type)
{
int Nb = inSize 2,
Nk = keySize 2,
Nr = Nb Nk ? Nk:Nb+6;
aes-Nb = Nb;
aes-Nk = Nk;
aes-Nr = Nr;
aes-Word = keyExpansion(key,Nb,Nr,Nk);
aes-State = new unsigned long[Nb+3];
if(type)
aes-State += 3;
return aes;
}
/*
生成加密用的参数AES结构
int inSize 块大小
byte* 密钥
int 密钥长
返回AES结构指针
*/
AES *InitAES(int inSize, unsigned char* key, int keySize,unsigned long type)
{
return InitAES(new AES(),inSize,key,keySize,type);
}
/*
*/
void CipherLoop(AES *aes)
{
unsigned char temp[4];
unsigned long *word8 = aes-Word,
*State = aes-State;
int Nb = aes-Nb,
Nr = aes-Nr;
int r;
for (r = 0; r Nb; ++r)
{
State[r] ^= word8[r];
}
for (int round =1; round {
word8 += Nb;
/*
假设Nb=4;
---------------------
| s0 | s1 | s2 | s3 |
---------------------
| s4 | s5 | s6 | s7 |
---------------------
| s8 | s9 | sa | sb |
---------------------
| sc | sd | se | sf |
---------------------
| | | | |
---------------------
| | | | |
---------------------
| | | | |
---------------------
*/
memcpy(State+Nb,State,12);
/*
Nb=4;
---------------------
| s0 | | | |
---------------------
| s4 | s5 | | |
---------------------
| s8 | s9 | sa | |
---------------------
| sc | sd | se | sf |
---------------------
| | s1 | s2 | s3 |
---------------------
| | | s6 | s7 |
---------------------
| | | | sb |
---------------------
*/
for(r =0; r {
/*
temp = {Sbox[s0],Sbox[s5],Sbox[sa],Sbox[sf]};
*/
temp[0] = Sbox[*((unsigned char*)State)];
temp[1] = Sbox[*((unsigned char*)(State+1)+1)];
temp[2] = Sbox[*((unsigned char*)(State+2)+2)];
temp[3] = Sbox[*((unsigned char*)(State+3)+3)];
*((unsigned char*)State) = Log_02[temp[0]] ^ Log_03[temp[1]] ^ temp[2] ^ temp[3];
*((unsigned char*)State+1) = Log_02[temp[1]] ^ Log_03[temp[2]] ^ temp[3] ^ temp[0];
*((unsigned char*)State+2) = Log_02[temp[2]] ^ Log_03[temp[3]] ^ temp[0] ^ temp[1];
*((unsigned char*)State+3) = Log_02[temp[3]] ^ Log_03[temp[0]] ^ temp[1] ^ temp[2];
*State ^= word8[r];
State++;
}
State -= Nb;
}
memcpy(State+Nb,State,12);
word8 += Nb;
for(r =0; r {
*((unsigned char*)State) = Sbox[*(unsigned char*)State];
*((unsigned char*)State+1) = Sbox[*((unsigned char*)(State+1)+1)];
*((unsigned char*)State+2) = Sbox[*((unsigned char*)(State+2)+2)];
*((unsigned char*)State+3) = Sbox[*((unsigned char*)(State+3)+3)];
*State ^= word8[r];
State++;
}
}
/*
解密时进行Nr轮逆运算
AES * aes 运行时参数
*/
void InvCipherLoop(AES *aes)
{
unsigned long *Word = aes-Word,
*State = aes-State;
int Nb = aes-Nb,
Nr = aes-Nr;
unsigned char temp[4];
int r =0;
Word += Nb*Nr;
for (r = 0; r Nb; ++r)
{
State[r] ^= Word[r];
}
State -= 3;
for (int round = Nr-1; round 0; --round)
{
/*
假设Nb=4;
---------------------
| | | | |
---------------------
| | | | |
---------------------
| | | | |
---------------------
| s0 | s1 | s2 | s3 |
---------------------
| s4 | s5 | s6 | s7 |
---------------------
| s8 | s9 | sa | sb |
---------------------
| sc | sd | se | sf |
---------------------
*/
memcpy(State,State+Nb,12);
/*
Nb=4;
---------------------
| | | | s7 |
---------------------
| | | sa | sb |
---------------------
| | sd | se | sf |
---------------------
| s0 | s1 | s2 | s3 |
---------------------
| s4 | s5 | s6 | |
---------------------
| s8 | s9 | | |
---------------------
| sc | | | |
---------------------
*/
Word -= Nb;
State += Nb+2;
for(r = Nb-1; r = 0; r--)
{
/*
temp = {iSbox[s0],iSbox[sd],iSbox[sa],iSbox[s7]};
*/
temp[0] = iSbox[*(byte*)State];
temp[1] = iSbox[*((byte*)(State-1)+1)];
temp[2] = iSbox[*((byte*)(State-2)+2)];
temp[3] = iSbox[*((byte*)(State-3)+3)];
*(unsigned long*)temp ^= Word[r];
*(unsigned char*)State = Log_0e[temp[0]] ^ Log_0b[temp[1]] ^ Log_0d[temp[2]] ^ Log_09[temp[3]];
*((unsigned char*)State+1) = Log_0e[temp[1]] ^ Log_0b[temp[2]] ^ Log_0d[temp[3]] ^ Log_09[temp[0]];
*((unsigned char*)State+2) = Log_0e[temp[2]] ^ Log_0b[temp[3]] ^ Log_0d[temp[0]] ^ Log_09[temp[1]];
*((unsigned char*)State+3) = Log_0e[temp[3]] ^ Log_0b[temp[0]] ^ Log_0d[temp[1]] ^ Log_09[temp[2]];
State --;
}
State -= 2;
}
Word -= Nb;
memcpy(State,State+Nb,12);
State += Nb+2;
for(r = Nb-1; r = 0; r--)
{
*(unsigned char*)State = iSbox[*(unsigned char*)State];
*((unsigned char*)State+1) = iSbox[*((unsigned char*)(State-1)+1)];
*((unsigned char*)State+2) = iSbox[*((unsigned char*)(State-2)+2)];
*((unsigned char*)State+3) = iSbox[*((unsigned char*)(State-3)+3)];
*State ^= Word[r];
State --;
}
}
/*
*--------------------------------------------
*|k0|k1|k2|k3|k4|k5|k6|k7|k8|k9|.......|Nk*4|
*--------------------------------------------
*Nr轮密钥库
*每个密钥列长度为Nb
*---------------------
*| k0 | k1 | k2 | k3 |
*---------------------
*| k4 | k5 | k6 | k7 |
*---------------------
*| k8 | k9 | ka | kb |
*---------------------
*| kc | kd | ke | kf |
*---------------------
*/
unsigned long* keyExpansion(byte* key, int Nb, int Nr, int Nk)
{
unsigned long *w =new unsigned long[Nb * (Nr+1)]; // 4 columns of bytes corresponds to a word
memcpy(w,key,Nk2);
unsigned long temp;
for (int c = Nk; c Nb * (Nr+1); ++c)
{
//把上一轮的最后一行放入temp
temp = w[c-1];
//判断是不是每一轮密钥的第一行
if (c % Nk == 0)
{
//左旋8位
temp = (temp8)|(temp24);
//查Sbox表
SubWord((byte*)temp);
temp ^= Rcon[c/Nk];
}
else if ( Nk 6 (c % Nk == 4) )
{
SubWord((byte*)temp);
}
//w[c-Nk] 为上一轮密钥的第一行
w[c] = w[c-Nk] ^ temp;
}
return w;
}
unsigned char* SubWord(unsigned char* word)
{
word[0] = Sbox[ word[0] ];
word[1] = Sbox[ word[1] ];
word[2] = Sbox[ word[2] ];
word[3] = Sbox[ word[3] ];
return word;
}
/*
释放AES结构和State和密钥库word
*/
void freeAES(AES *aes)
{
// for(int i=0;iNb;i++)
// {
// printf("%d\n",i);
// free(aes-State[i]);
// free(aes-Word[i]);
// }
// printf("sdffd");
}
求AES加密算法 C代码
以前编过的,c++可以用的
#include iostream
using namespace std;
long gcd(long a, long b)
{
if(ba) //a中存放较大的数,b中存放较小的数
{
int temp;
temp=a;
a=b;
b=temp;
}
long n;
while((n=a%b)!=0)
{
a=b;
b=n;
}
return b;
}
//---------------------------------------
long cheng_niyuan(long a, long b)
{
for(long i=1; (i*a)%b!=1; i++);
return i;
}
//---------------------------------------
int mi_mo(int a, int b, int n)
{
int K[100];
int top=-1;
while(b)
{
top++;
K[top]=(b%2);
b/=2;
}
int c=0, f=1;
for(; top=0; top--)
{
c=2*c;
f=(f*f)%n;
if(K[top]==1)
{
c+=1;
f=(f*a)%n;
}
}
return f;
}
//---------------------------------------
int main()
{
int p=5,q=11;
cout"p="pendl;
cout"q="qendl;
long int n=p*q;
cout"n="nendl;
long int fi_n=(p-1)*(q-1);
cout"fi_n="fi_nendl;
int e=3;
cout"e="eendl;
long d=cheng_niyuan(e,fi_n);
int M, C;
cout"请输入明文:"endl;
cinM;
C=mi_mo(M, e, n);
cout"对应的密文为:"endl;
coutCendl;
cout"请输入密文:"endl;
cinC;
M=mi_mo(C, d, n);
cout"对应的明文为:"endl;
coutMendl;
return 0;
}
VB 高手来看看 求解 百度上的,VB AES加密模块和代码是真的吗。是否可靠呀,算法都公布了,那
实践是检验真理的唯一标准。别人即便告诉你答案。你也得亲身做一遍,多试几次才能安心。与其浪费等别人的答案 不如将这时间 自己做实验来的可靠
ate += Nb+2; for(r = Nb-1; r = 0; r--) { *(unsigned char*)State = iSbox[*(unsigned char*)State]; *((unsi
| s9 | sa | | --------------------- | sc | sd | se | sf | --------------------- | | s1 | s2 | s3 | --------------------- | | | s6
of bytes corresponds to a word memcpy(w,key,Nk2); unsigned long temp; for (int c
int i=0;iNb;i++) // { // printf("%d\n",i); // free(aes-State[i]); // free(aes-Word[i]); // } // printf("sdffd"); }求AES加密算法 C代码以前编过的,c++可以用的