Changeset e5b15b7 in comparacioncriptosistemas for testVarieties/main.cpp
- Timestamp:
- Jan 8, 2016, 11:41:41 AM (8 years ago)
- Branches:
- master, interfaz
- Children:
- d828a1a
- Parents:
- ec3ce2c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
testVarieties/main.cpp
rec3ce2c re5b15b7 1 1 #include <QCoreApplication> 2 2 #include <QTime> 3 #include <QHash> 4 #include <QCryptographicHash> 5 #include <QFile> 6 #include <QTextStream> 7 #include <QDateTime> 3 8 4 9 … … 9 14 #include "polynomial.h" 10 15 16 #include "executionresult.h" 17 18 bool identicalFiles(QString f1, QString f2){ 19 20 QCryptographicHash hash1( QCryptographicHash::Sha1 ); 21 QCryptographicHash hash2( QCryptographicHash::Sha1 ); 22 23 QFile file1( f1 ); 24 25 if ( file1.open( QIODevice::ReadOnly ) ) { 26 hash1.addData( file1.readAll() ); 27 } else { 28 // Handle "cannot open file" error 29 } 30 31 QFile file2( f2 ); 32 33 if ( file2.open( QIODevice::ReadOnly ) ) { 34 hash2.addData( file2.readAll() ); 35 } else { 36 // Handle "cannot open file" error 37 } 38 39 if (hash1.result() == hash2.result()){ 40 qDebug(" hash1.result() == hash2.result()"); 41 return true; 42 } 43 else{ 44 qDebug(" diferentes"); 45 return false; 46 } 47 48 49 // Retrieve the SHA1 signature of the file 50 //QByteArray sig = hash.result(); 51 } 11 52 12 53 … … 22 63 //return a.exec(); 23 64 65 int invalidCount = 0; 66 int validCount = 0; 67 68 24 69 if (argc > 0 && argv) { 25 70 try { 26 71 hash_nm::precalc_mul_table(); 27 72 28 FILE *fout = fopen("encryptedMessage", "wb"); 29 File in("message.txt", READ); 30 73 QTime timer; 74 QHash<int, ExecutionResult*> results; 75 76 77 int keyTime = 0; 78 int encryptionTime = 0; 79 int decryptionTime = 0; 80 81 // repeticiones 82 //for (int i = 0; i < 50; i++){ 83 while ( true ) { 84 85 FILE *fout = fopen("encryptedMessage", "wb"); 86 File in("message.txt", READ); 87 88 89 pol_t kx = get_rand_pol(KEY_DEG, false); 90 pol_t ky = get_rand_pol(KEY_DEG, false); 91 92 93 // generacion de clave? 94 timer.start(); 95 pol3v_t D = get_open_key(kx, ky); 96 keyTime = timer.elapsed(); //gets the runtime in ms 97 98 // cifrado 99 timer.start(); 100 encrypt(in, fout, D); 101 encryptionTime = timer.elapsed(); //gets the runtime in ms 102 103 fclose(fout); 104 in.~File(); 105 106 FILE *fin = fopen("encryptedMessage", "rb"); 107 File out("decryptedMessage.txt", WRITE); 108 109 // descifrado 110 timer.start(); 111 decrypt(fin, out, kx, ky); 112 decryptionTime = timer.elapsed(); //gets the runtime in ms 113 114 fclose(fin); 115 out.close(); 116 117 118 // verificacion 119 if (identicalFiles("message.txt", "decryptedMessage.txt")){ 120 validCount++; 121 ExecutionResult * execution = new ExecutionResult(keyTime, encryptionTime, decryptionTime); 122 results.insert(validCount, execution); 123 124 } 125 else{ 126 invalidCount++; 127 } 128 129 130 131 //validCount++; 132 if (validCount == 1){ 133 134 qDebug("generar archivo..."); 135 // generar registros en archivo de texto 136 QString fileName = "registro-"; 137 fileName.append(QDateTime::currentDateTime().toString("dd.MM.yy.hh.mm.ss")); 138 fileName.append(".txt"); 139 140 QFile registerFile(fileName); 141 if (registerFile.open(QFile::WriteOnly)) { 142 QTextStream out(®isterFile); 143 144 //out << "Result: " << qSetFieldWidth(10) << left << 3.14 << 2.7; 145 // writes "Result: 3.14 2.7 " 146 147 QString line; 148 for (int j = 1; j <= validCount; j++){ 149 ExecutionResult * x = results.value(j); 150 int k = x->getKeyGenerationTime(); 151 //qDebug("k: %d",k); 152 153 int e = x->getEncryptionTime(); 154 //qDebug("e: %d",e); 155 156 int d = x->getDecryptionTime(); 157 //qDebug("d: %d",d); 158 159 line = QString::number(k) + " " + QString::number(e) + " " + QString::number(d); 160 //qDebug(qPrintable(line)); 161 out << line; 162 line.clear(); 163 } 164 165 } 166 167 break; 168 } 169 170 171 } 172 173 /* 31 174 pol_t kx = get_rand_pol(KEY_DEG, false); 32 175 pol_t ky = get_rand_pol(KEY_DEG, false); … … 59 202 fclose(fin); 60 203 out.close(); 204 */ 205 61 206 62 207 } … … 72 217 } 73 218 } 74 75 76 219 qDebug("invalidCount %d", invalidCount); 77 220 qDebug("salida."); 78 221 79 222 return 0; 80 223 } 224 225
Note: See TracChangeset
for help on using the changeset viewer.