工作闲暇时间,把写内容过程中较好的内容珍藏起来,下面的资料是关于C++简单数据加密算法实现加密和解密的内容,应该是对小伙伴有用。
This is a program for Encryption and Decryption
This program uses the Simple Data Encryption Standard (SDES) Algorithm.
This Algo takes 8-bits of plaintext at a time and produces 8-bits of ciphertext.
It uses 10-bits of key for Encryption and Decryption.
Developed by : Vivek Kumar (vivek_kumar_bt@yahoo.co.in)
Created on : 31 March 2005
Last Modified on : 10 April 2005
Any sort of suggetions/comments are most welcome at vivek_kumar_bt@yahoo.co.in
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<assert.h>
void menuEn();
void menuDe();
int DoEnDe(int);
class SDES
{
private:
char KEY[11],K1[9],K2[9],IPOutput[9],InvIPOutput[9];
char F1Output[9],F2Output[9];
char INPUT_BIT[9],OUTPUT_BIT[9];
public:
unsigned char INPUT,OUTPUT;
~SDES();
void GenerateKeys();
void conv_to_bits(unsigned char );
void DES_Encryption(unsigned char );
void DES_Decryption(unsigned char );
void SDES::GetChar();
};
{
int i;
{
printf("nInValid Key-Length %s %d",key,strlen(key));
getch();
exit(1);
}
{
KEY[i]=key[i];
}
KEY[10]='0';
}
void SDES::GenerateKeys()
{
int i;
for (i=0;i<10;i++)
P10_OP[i]=KEY[P10[i]-1];
P10_OP[10]='0';
for (i=0;i<5;i++)
{
P10LEFT[i]=P10_OP[i];
P10RIGHT[i]=P10_OP[i+5];
}
P10LEFT[5]='0';
P10RIGHT[5]='0';
pl=new char[6];
pr=new char[6];
pl=Left_Shift(P10LEFT,1);
pr=Left_Shift(P10RIGHT,1);
for (i=0;i<5;i++)
{
plpr[i]=pl[i];
plpr[i+5]=pr[i];
}
plpr[10]='0';
for (i=0;i<8;i++)
K1[i]=plpr[P8[i]-1];
pl1=Left_Shift(pl,2);
pr1=Left_Shift(pr,2);
for (i=0;i<5;i++)
{
plpr[i]=pl1[i];
plpr[i+5]=pr1[i];
}
plpr[10]='0';
for (i=0;i<8;i++)
{