C++实现仿射加密法
生活随笔
收集整理的這篇文章主要介紹了
C++实现仿射加密法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
創建Crypt.h頭文件
#include <string> #include <string.h> using namespace std;const string SYMBOL="ABCDEFGHIJKLMNOPQRSTUVWXYZ";string affineEncrypt(const char *data,int keyA,int keyB);//聲明函數string affineEncrypt(const char *data,int keyA,int keyB)//實習函數 {string result;int len = strlen(data);for(int i=0;i<len;i++){int pos = SYMBOL.find(data[i]);if(pos!=-1){int offset = (keyA*pos+keyB)%26;result+=SYMBOL[offset];}else{result+=data[i];}}return result; }主程序“
#include <iostream> #include <string> #include "Crypt.h" int main() {char data[]="THE NATIONAL SECURITY AGENCY";//明文string ret = affineEncrypt(data,11,23);//加密明文cout << ret << endl;//輸出密文return 0; }總結
以上是生活随笔為你收集整理的C++实现仿射加密法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python判断计算机是否有网络连接
- 下一篇: C++使用类静态成员跟踪对象的个数