论坛: 编程破解 标题: hill 复制本贴地址    
作者: hardwater [hardwater]    论坛用户   登录
#include<iostream.h>
#include<iomanip.h>
///////////////////////////////////////////////////////////////////////
int gcd(int big,int small)
{
int temp=1,x=1;
while(x!=0)
{
temp=big/small;
x=big-temp*small;
big=small;
small=x;
}
return big;
}//求最大公约数
/////////////////////////////////////////////////////////////////////////
void main()

int A[26]={1,0,9,0,21,0,15,0,3,0,19,0,0,0,7,0,23,0,11,0,5,0,17,0,25,0};
//Z(26)下的逆元表,Z(26)的既约剩余系有数,而非Z(26)的既约剩余系书为0

  const int m=4,n=4;
//int Array[4][4]={{8,6,9,5},{6,9,5,10},{5,8,4,9}, {10,6,11,4}};
// int Array[4][4]={{8,6,9,5}, {5,8,4,9},{6,9,5,10},{10,6,11,4}};
  int Array[4][4]={{10,6,11,4},{8,6,9,5}, {5,8,4,9},{6,9,5,10}};
  int Arrayp[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};

for(int f=0;f<m;f++)
  {
        for(int g=0;g<n;g++)
        cout<<Array[f][g]<<setw(6)<<"    ";
        cout<<endl;
  }//输出待求逆数组
cout<<"输出待求逆数组--------------------------"<<endl;
    int Temp[4][8];

        for(int i=0;i<m;i++)
  for(int j=0;j<2*n;j++)
  {
    if(j<n)
      Temp[i][j]=Array[i][j];
    else
          Temp[i][j]=0;
          if(j-i==m)
      Temp[i][j]=1;
  }//初始化Temp数组与单位矩阵结合
        for(int p=0;p<m;p++)
{
      for(int q=0;q<2*n;q++)
      cout<<setiosflags(ios::left)
      <<setw(4)
  <<Temp[p][q]<<"    ";
          cout<<endl;
}
cout<<"输出与单位阵的结合数组--------------------------"<<endl;
//输出Temp数组检查
   


      int xx=0; //控制换行退返回0
begin:
for(int w=xx;w<m;w++)
  {
////////////////////////////////////////////////////////////////////////
if(gcd(26,Temp[w][w])!=1)
  { 
  int finder=0;
    for(int p=w+1;p<m;p++)
  {   
    finder++;
                    if(gcd(26,Temp[p][w])==1)
                          break;
  }//find finder

  for(int k=0;k<2*n;k++)
  { 
    int ttemp=0;
                        ttemp=Temp[w][k];
    Temp[w][k]=Temp[w+finder][k];
    Temp[w+finder][k]=ttemp;
}
  for(int pp=0;pp<m;pp++)
  {
            for(int q=0;q<2*n;q++)
  cout<<setw(8)<<Temp[pp][q] ;
  cout<<endl;
  }//检查换行后的情况
cout<<"检查到对角元为非换行后Z(26)的既约剩余系就换行----------"<<endl;
  for(int f=0;f<m;f++)
  {
                              for(int g=0;g<n;g++)
                            Array[f][g]=Temp[f][g];
  }//刷新Array因为Temp换行后Array还未刷新
  goto begin;
  }  // if 
//////////////////////检查Temp[w][w](对角元)是否为Z(26)的既约剩余系
  for(int u=w;u<2*n;u++)
  { 
 
  Temp[w][u]=(Temp[w][u]*A[Array[w][w]-1])%26;
  }
          for(int e=w+1;e<m;e++)
for(int r=0;r<2*n;r++)
{
          Temp[e][r]=(Temp[e][r]-Temp[w][r]*Array[e][w])%26;
    if(Temp[e][r]<0)
          Temp[e][r]=Temp[e][r]+26;//计算机的模有负的
 
}
  for(int f=0;f<m;f++)
  {
                              for(int g=0;g<n;g++)
                            Array[f][g]=Temp[f][g];
  }//为了保证特门牌temp 数组的值不停的在刷新,注意编程是数值的正确性
for(int p=0;p<m;p++)
{
              for(int q=0;q<2*n;q++)
        cout<<setw(8)<<Temp[p][q] ;
            cout<<endl;
}
          cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl;//输出检查
  }//for做消去下三角矩阵工作

//***************************************************************
   
  for(int x=m-1;x>0;x--)
  {
  for(int e=x-1;e>=0;e--)
      for(int r=x;r<2*n;r++)
  {
          Temp[e][r]=(Temp[e][r]-Temp[x][r]*Array[e][x])%26;
      if(Temp[e][r]<0)
  Temp[e][r]=Temp[e][r]+26;//计算机的模有负的
  }
  for(int f=0;f<m;f++)
  {
                    for(int g=0;g<n;g++)
                  Array[f][g]=Temp[f][g];
  }//为了保证特门牌temp 数组的值  不停的在刷新,注意编程是数值的正确性
 
  for(int p=0;p<m;p++)
  {
            for(int q=0;q<2*n;q++)
 
                             
                cout<<setw(8)<<Temp[p][q] ;
 
                cout<<endl;
  }
          cout<<"**********************************"<<endl;//输出检查
  }//for做消去上三角矩阵工作
 
}//结束

地主 发表时间: 11/04 17:08

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号