當前位置:編程學習大全網 - 編程軟體 - C語言中的數據加密(跪求)

C語言中的數據加密(跪求)

下面是個例子,對12345678加密。

想對哪個8位數加密,調ProcessInt這個函數就可以了。

如果8位內的任意整數的話,樓主做做改動即可,不難實現。

程序考慮到讓樓主看的清楚,並沒有將效率寫到最大。

#include <stdio.h>

#include <iostream>

#include <windows.h>

#include <math.h>

using namespace std;

void ProcessInt(int* piInt)

{

int iArray[8];

int iResult = (*piInt);

int iTmp = *piInt;

for (int i = 0; i < 8; i++)

{

iResult = iResult / (int)pow(10, 8 - 1 - i);

iArray[i] = iResult;

iResult = iTmp - iResult * (int)pow(10, 8 - 1 - i);

iTmp = iResult;

}

//1.sequence

//2.replace the number by plus 5 and then div 10

for (int i = 0; i < 8; i++)

{

iArray[i] = (iArray[i] + 5) % 10;

}

//3.first->last, last->first

//4.construct the number

iResult = iArray[0] * (int)pow(10, 7);

iResult = iResult + iArray[6] * (int)pow(10, 6);

iResult = iResult + iArray[5] * (int)pow(10, 5);

iResult = iResult + iArray[4] * (int)pow(10, 4);

iResult = iResult + iArray[3] * (int)pow(10, 3);

iResult = iResult + iArray[2] * (int)pow(10, 2);

iResult = iResult + iArray[1] * (int)pow(10, 1);

iResult = iResult + iArray[7];

*piInt = iResult;

}

void main()

{

int i = 12345678;

ProcessInt(&i);

printf("加密後的數據是:%d\n", i);

}

  • 上一篇:識別文字的軟件
  • 下一篇:為什麽淘寶綁定不了返利平臺_淘寶天貓返利操作視頻教程
  • copyright 2024編程學習大全網