fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <sstream> //this is where istringstream is defined
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int x(unsigned int tab[],int numBit){
  9. return ((tab[numBit / 32] >> (numBit % 32))&1);
  10. }
  11.  
  12. void set(unsigned int tab[],unsigned int numBit,unsigned int v){
  13. unsigned int t=(unsigned int)v<<(numBit%32);
  14. unsigned int m=(unsigned int)1<<(numBit%32);
  15.  
  16. unsigned int o=(tab[numBit / 32]);
  17. o=o&~m;
  18. tab[numBit / 32] = o | t;
  19. }
  20.  
  21. struct Formule{
  22. unsigned int formuleL[512];
  23. unsigned int formuleR[512];
  24. unsigned int fsp=0;
  25.  
  26. void add(unsigned int a,unsigned int b){
  27. formuleL[fsp]=a;
  28. formuleR[fsp]=b;
  29. fsp++;
  30. }
  31. };
  32.  
  33. int main(){
  34. int size;
  35.  
  36. cout<<"funWithFormule"<<endl;
  37. string is="256\n 320a18d5 b61b13f6 1aaaa61c 0afe2a41 1a4ff107 84cc2efc 956ff31d fa595299 33749a7f 6cc9659d dc503569 ef4d0ef5 73b746c5 b8fb36d3 7616e9d6 b21251c4\n";
  38. std::istringstream sin(is);
  39. sin >> size;
  40.  
  41. unsigned int* a = new unsigned int[size / 16]; // <- input tab to encrypt
  42. unsigned int* b = new unsigned int[size / 16]; // <- output tab
  43. Formule *formule=new Formule[size*2];
  44. for(int i=0;i<size* 2;i++){
  45. formule[i].fsp=0;
  46. }
  47. cout<<"funWithFormule begin read"<<endl;
  48.  
  49. for (int i = 0; i < size / 16; i++) { // Read size / 16 integers to a
  50. sin >> hex >> a[i];
  51. }
  52.  
  53. for (int i = 0; i < size / 16; i++) { // Write size / 16 zeros to b
  54. b[i] = 0;
  55. }
  56. for (int i = 0; i < size; i++)
  57. for (int j = 0; j < size; j++){
  58. formule[i+j].add(i,j+size);
  59.  
  60. //set(b,i+j, x(b,i+j)^(x(a,i)&x(a,j+size)));
  61. }
  62. cout<<"funWithFormule apply formulaes"<<endl;
  63. for(int i=0;i<size*2;i++){
  64. //cout<<i<<endl;
  65. unsigned int xo=0;
  66. for(int k=0;k<formule[i].fsp;k++){
  67. unsigned int v= x(a,formule[i].formuleL[k]) & x(a,formule[i].formuleR[k]);
  68. xo^=v;
  69. }
  70.  
  71. set(b,i, xo );
  72. }
  73.  
  74. for(int i = 0; i < size / 16; i++)
  75. cout << hex << b[i] << " "; // print result
  76.  
  77. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
funWithFormule
funWithFormule begin read
funWithFormule apply formulaes
4af6fc33 39029380 465c5267 c72f6a8b 906e6d0 ca60550f 14a5e47c 42ad10fb 4a3bb446 bb74360a 5ea02b9c 23c68553 3fade253 e270ba24 39e141ad 6c38c43d