C++简单数据加密算法实现加密和解密的代码

工作闲暇时间,把写内容过程中较好的内容珍藏起来,下面的资料是关于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++)
    {
  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值