⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 一个简单的加密算法kaiser(c语言实现).txt

📁 一个简单的加密算法Kaiser(C语言实现)
💻 TXT
字号:
// Kaiser.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <string.h>
#include <stdio.h>
#define MAX 256
#define KEY 17    //密钥
char cipher(char sourceChar, int Key)  //加密算法
...{
    return (sourceChar + Key) % MAX;
}

char decipher(char sourceChar, int Key)//解密算法
...{
    return (sourceChar - Key + MAX) % MAX;
}

int _tmain(int argc, _TCHAR* argv[])
...{

    FILE *fp_plaintext;
    FILE *fp_ciphertext;
    FILE *fp_deciphertext;
    

char source_char[50000] = ...{0};       //存放源码
char cipher_char[50000] = ...{0};        //存放加密码
char decipher_char[50000] = ...{0};    //存放解密码
    int source_size = 0;                               //字符个数
    
    fp_plaintext = fopen("test.txt","r+");     //打开存放源码的文件test.txt进行"读"操作
    while((source_char[source_size] = fgetc(fp_plaintext))!=EOF)        //逐个取test.txt中的字符放到
                                                                                                                             source_char[source_size]中
    {
        source_size++;                        //字符个数source_size累加
    }
    printf(" The length of test.txt is %d ",source_size);
    fclose(fp_plaintext);                    //关闭文件

    printf(" test.txt: ");
    for(long i = 0; i < source_size; i++)
    ...{
        cipher_char[i] = cipher(source_char[i] , KEY);//对source_char[i]进行加密然后放到cipher_char[i]中
        printf("%c",source_char[i]);                 //打印原文source_char[i]
    }
    
    fp_ciphertext = fopen("fp_ciphertext.txt","w");//将已加密的数据cipher_char[i]存放到fp_ciphertext.txt中
    fprintf(fp_ciphertext,cipher_char);

    printf(" fp_ciphertext.txt: ");               //打印密文文件fp_ciphertext.txt
    for(long i = 0; i < source_size; i++)
    ...{
        printf("%c ",cipher_char[i]);
    }
    fclose(fp_ciphertext);

    source_size = 0;
    fp_ciphertext = fopen("fp_ciphertext.txt","r+");//打开密文fp_ciphertext.txt进行"读"
    while((cipher_char[source_size] = fgetc(fp_ciphertext))!=EOF)
    ...{
        source_size++;
    }
    fclose(fp_ciphertext);

    for(long i = 0; i < source_size; i++)
    ...{
        decipher_char[i] = decipher(cipher_char[i] , KEY);//将密文cipher_char[i]解密到明文decipher_char[i]中        
    }

    printf(" fp_deciphertext.txt: ");//输出解密后的明文decipher_char[i]
    for(long i = 0; i < source_size; i++)
    ...{
        printf("%c ",decipher_char[i]);
    }
    
    fp_deciphertext = fopen("fp_deciphertext.txt","w");//将解密后的明文decipher_char[i]存放到fp_deciphertext.txt文件中
    fprintf(fp_deciphertext,decipher_char);
    fclose(fp_deciphertext);
    getchar();
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -