中国地质大学信息安全实习Word文档格式.docx
《中国地质大学信息安全实习Word文档格式.docx》由会员分享,可在线阅读,更多相关《中国地质大学信息安全实习Word文档格式.docx(31页珍藏版)》请在冰豆网上搜索。
,string&
);
sutration(string&
multplication(string&
division(string&
voidshow();
voidBigFigueInterface();
string&
revese(string&
friendistream&
operator>
>
(istream&
i,BigFigure&
a){
returni>
a.um1>
a.operation>
a.num2;
~BigFigure(){}
};
voidBigFigue:
:
show()
{
cout<
<
"
结果是:
"
outcome<
endl;
}
voidBigFigure:
BigFigureInterface()
BigFiurea;
**************************************************************************"
大数的运算"
注意事项:
1.输入形式为:
A[空格或换行]O[空格或换行]B。
2.1中A、B为大数,O为运算符(如输入:
123456789/432432)。
3.既然处理大数,就没必要输入小数点位了。
cout<
4.加减不能处理负号,乘除可以。
5.异或,非。
。
请按照上述规则输入:
cin>
a;
while(a.operation!
='
0'
){
switch(a.opation){
case'
+'
a.pus(anum1,anum2);
a.show();
break;
-'
a.subtration(a.num1,a.num2);
*'
a.multiplication(a.num1,a.num2);
/'
a.division(a.num1,a.num2);
default:
a.operation<
isnotArithmeticOperation(不是运算符!
)"
cout<
请按照上述规则输入你要计算的下一组数据:
ci>
syste("
cl);
//system("
pause"
string&
BigFiure:
s){
charc;
intt=s.size();
for(inti=0;
i<
t/2;
i++){
cs[i];
s[i]=s[t-i-1];
s[t-i-1]=c;
returns;
BgFigure:
plus(string&
str1,string&
str2){//加法运算,未处理符号
intin=0,i,t=0;
strintemp;
str1=revese(str1);
str2=revese(str2);
min=str1.size()<
str2.size()?
str1.size():
str2.size();
for(i=0;
min;
temp+=(str1[i]+str2[i]-96+t)%10+48;
t=(str1[i]+str2[i]-96+t)/10;
if(min==str1.size()){
while(i<
str2.size()){
temp+=(str2[i]+t-48)%10+48;
t=(str2[i]-48+t)/10;
i++;
if(t)temp+='
1'
else{
while(i<
str1.size()){
temp+=(str1[i]+t-48)%10+48;
t=(str1[i]-48+t)/10;
outcome=revese(temp);
returnoutcome;
string&
BigFigure:
subtration(string&
str2)
{//减法运算,未处理符号
intmin=0,flag,i,t=0;
stringtemp;
if(str1.size()>
str2.size()||(str1.size()==str2.size()&
&
pare(str2)==1)){
flag=0;
min=str2.size();
elseif(str1.size()==str2.size()){
if(!
pare(str2)){
outcome='
returnoutcome;
}
if(pare(str2)==-1){
temp=str1;
str1=revese(str2);
str2=revese(temp);
flag=1;
min=str2.size();
temp=str1;
str1=revese(str2);
str2=revese(temp);
flag=1;
min=str2.size();
if(str1[i]-t<
str2[i]){
temp+=str1[i]+10-t-str2[i]+48;
t=1;
temp+=str1[i]-t-str2[i]+48;
t=0;
if(!
t){
while(i<
temp+=str1[i];
if(str1[i]!
){temp+=str1[i]-t;
elsetemp+='
9'
strings;
for(unsignedintk=temp.size()-1;
k>
=0;
k--){
if(temp[k]!
for(intn=k;
n>
n--)
s+=temp[n];
if(flag)s='
+s;
outcome=s;
BigFigure:
multiplication(string&
str2){//乘法运算,已处理符号
charc='
flag=0;
stringtemp1,temp2="
if(str1[0]=='
||str2[0]=='
){flag++;
str1.erase(0,1);
if(str2[0]=='
str2.erase(0,1);
for(unsignedinti=0;
str2.size();
c='
for(unsignedintj=0;
j<
str1.size();
j++){
temp1+=((str2[i]-48)*(str1[j]-48)+c-48)%10+48;
c=((str2[i]-48)*(str1[j]-48)+c-48)/10+48;
if(c!
)temp1+=c;
temp1=revese(temp1);
for(intk=0;
k<
i;
k++)
temp1+='
temp2=plus(temp1,temp2);
if(flag%2)temp2='
+temp2;
outcome=temp2;
division(string&
str2){//除法运算,已处理符号
intstr=0,flag=0,flag1=0,flag2=0;
stringtemp,temps,tempt;
if(str2=="
Inf"
1"
||str1=="
outcome=str1;
i++){//整除处理
str=0;
if(temp[0]=='
)temp.erase(0,1);
if(temp.size()>
str2.size()||
(temp.size()==str2.size()&
pare(str2)>
=0)){
while(temp.size()>
(temp.size()==str2.size()&
tempt=str2;
temp=subtration(temp,tempt);
str++;
temps+=str+48;
elseif(temp.size()==str2.size()&
pare(str2)==0)temps+='
elsetemps+='
flag1=temps.size();
if(temp!
="
&
precision)temps+='
.'
=precision&
temp!
i++){//小数后位的处理
temp+='
pare(str2)>
flag2=temps.size()-2;
if(temps[temps.size()-1]>
5'
flag2-flag1==precision){//四舍五入处理
temps.erase(flag1,1);
temps.erase(temps.size()-1,1);
temp="
temps=plus(temps,temp);
if(temps.size()>
flag2)temps.insert(flag1+1,1,'
elsetemps.insert(flag1,1,'
elseif(flag2-flag1==precision)temps.erase(temps.size()-1,1);
for(unsignedintk=0;
temps.size();
k++){//左端去零处理
if(temps[k]!
||temps[k+1]=='
n<
n++)
temp+=temps[n];
if(flag%2)temp='
+temp;
outcome=temp;
intmain(){//主函数
BigFigurea;
a.BigFigureInterface();
return0;
s.huH^,bB!
V
使用VC++编程语言编写一个程序,实现DES算法,包括以下环节,密钥通过随机函数产生,并应用密文反馈(CFB)工作模式和输出反馈(OFB)工作模式进行加密、解密和输出。
截图
#include"
stdio.h"
math.h"
stdax.h"
staticvoidscrunch(unsignedchar*,unsignedlong*);
staticvoidunscrun(unsignedlong*,unsignedchar*);
staticvoiddesfunc(unsignedlong*,unsignedlong*);
staticvoidcookey(unsignedlong*);
staticunsignedlongKnL[32]={0L};
staticunsignedlongKnR[32]={0L};
staticunsignedlongKn3[32]={0L};
staticunsignedcharDf_Key[24]={
0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67};
staticunsignedshortbytebit[8]={
0200,0100,040,020,010,04,02,01};
staticunsignedlongbigbyte[24]={
0x800000L,0x400000L,0x200000L,0x100000L,
0x80000L,0x40000L,0x20000L,0x10000L,
0x8000L,0x4000L,0x2000L,0x1000L,
0x800L,0x400L,0x200L,0x100L,
0x80L,0x40L,0x20L,0x10L,
0x8L,0x4L,0x2L,0x1L};
/*UsethekeyschedulespecifiedintheStandard(ANSIX3.92-1981).*/
staticunsignedcharpc1[56]={
56,48,40,32,24,16,8,0,57,49,41,33,25,17,
9,1,58,50,42,34,26,18,10,2,59,51,43,35,
62,54,46,38,30,22,14,6,61,53,45,37,29,21,
13,5,60,52,44,36,28,20,12,4,27,19,11,3};
staticunsignedchartotrot[16]={
1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28};
staticunsignedcharpc2[48]={
13,16,10,23,0,4,2,27,14,5,20,9,
22,18,11,3,25,7,15,6,26,19,12,1,
40,51,30,36,46,54,29,39,50,44,32,47,
43,48,38,55,33,52,45,41,49,35,28,31};
voiddeskey(key,edf)/*ThankstoJamesGillogly&
PhilKarn!
*/
unsignedchar*key;
shortedf;
{
registerinti,j,l,m,n;
unsignedcharpc1m[56],pcr[56];
unsignedlongkn[32];
for(j=0;
j<
56;
j++){
l=pc1[j];
m=l&
07;
pc1m[j]=(key[l>
3]&
bytebit[m])?
1:
0;
}
for(i=0;
i<
16;
i++){
if(edf==DE1)m=(15-i)<
1;
elsem=i<
n=m+1;
kn[m]=kn[n]=0L;
for(j=0;
28;
l=j+totrot[i];
if(l<
28)pcr[j]=pc1m[l];
elsepcr[j]=pc1m[l-28];
}
for(j=28;
l=j+totrot[i];
if(l<
56)pcr[j]=pc1m[l];
elsepcr[j]=pc1m[l-28];
24;
if(pcr[pc2[j]])kn[m]|=bigbyte[j];
if(pcr[pc2[j+24]])kn[n]|=bigbyte[j];
cookey(kn);
return;
}
staticvoidcookey(raw1)
registerunsignedlong*raw1;
registerunsignedlong*cook,*raw0;
unsignedlongdough[32];
registerinti;
cook=dough;
i++,raw1++){
raw0=raw1++;
*cook=(*raw0&
0x00fc0000L)<
6;
*cook|=(*raw0&
0x00000fc0L)<
10;
*cook|=(*raw1&
0x00fc0000L)>
*cook++|=(*raw1&
0x00000fc0L)>
0x0003f000L)<
12;
0x0000003fL)<
0x0003f000L)>
4;
0x0000003fL);
usekey(dough);
voidcpkey(into)
reg