跪求一个加密小程序的题目,谢谢啦..急..

来源:百度知道 编辑:UC知道 时间:2024/06/28 09:18:06
某公司采用公用电话传递数据,数据为四位整数。传递过程加密,加密规则如下:每位数字加5,用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。显示加密后的四位整数。若正确输入六位密码,可显示出原整数值。
本人对编程一无所知,能不能直接给到一个4位的整数加密..谢..

下面是个例子,对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);