主题:用c++ builder 给文件加密
			 zsylyc
				 [专家分:0]  发布于 2005-07-05 17:15:00
 zsylyc
				 [专家分:0]  发布于 2005-07-05 17:15:00							
			请教,有哪位高手给写一段代码,我想给文本文件加密、解密。急急急
						
					 
		
			
回复列表 (共1个回复)
		
								
				沙发
				
					 firstddf [专家分:0]  发布于 2005-07-06 09:08:00
firstddf [专家分:0]  发布于 2005-07-06 09:08:00				
				//---------------------------------------------------------------------------
#pragma hdrstop
#include<iostream.h>
#include <conio.h>
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
 /*
 int a,q,b,g,s;
 cout<<"input the a:";
 cin>>a;
 if (999<a&&a<10000)
    {
     s=((a/1000+7)%10);
     g=(((a/100)%10+7)%10);
     q=(((a/10)%100+7)%10);
     b=((a%1000+7)%10);
     cout<<"a="<<a<<"  b="<<q<<b<<g<<s<<endl;
     }
 else
    cout<<"the number is error\n";
 getche();
 return 0;
 }
   */
 int a,b;
 cout<<"input the a:";
 cin>>a;
 if (0<a&&a<10000)
    {
     b=(a/1000+10-7)%10*10+((a/100)%10+10-7)%10*1+((a/10)%100+10-7)%10*100+(a/1%1000+10-7)%10*1000;
     cout<<"a="<<a<<"  b="<<b<<endl;
     }
 else
    cout<<"the number is error\n";
 getche();
 return 0;
}
//---------------------------------------------------------------------------
我刚作完个练习,可以帮我看一下吗?
原题是这样的
将每个位换成该位与7的和并用10求模。然后交换第一位与第三位,交换第二位与第四位。并打印加密后的整数。再写一个解密的,解密原先的四位数。
这个题我在加密时为了避免有0的情况,只好折开了四个数的输出,不知有不拆的方法吗?
在解密时
(a/1000+10-7)%10*10             q-s
((a/100)%10+10-7)%10*1          b-g
((a/10)%100+10-7)%10*100        s-q 那就((a/10)%100+10-7)%10*1000
(a/1%1000+10-7)%10*1000         g-b     (a/1%1000+10-7)%10*100
可是如何这样写解出来的千百就与原码换位了。
不知我是哪错了,希望高手能帮我一下?
     q-
							 
									
			
我来回复