Advertisement
Lauda

md5

Feb 13th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.41 KB | None | 0 0
  1. #ifndef BASE_H_INCLUDED
  2. #define BASE_H_INCLUDED
  3.  
  4. // Definicije tipova:
  5. typedef unsigned int uint32;    // Pretpostavicemo da ce ovo biti 32-bita
  6. typedef unsigned char uint1;    //  - || - 8-bita
  7. enum {
  8.     S11 = 7, S12 = 12, S13 = 17, S14 = 22,
  9.     S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  10.     S31 = 4, S32 = 11, S33 = 16, S34 = 23,
  11.     S41 = 6, S42 = 10, S43 = 15, S44 = 21,
  12.     blockSize = 64
  13. };
  14.  
  15. #endif // BASE_H_INCLUDED
  16.  
  17.  
  18. #ifndef MD5_H_INCLUDED
  19. #define MD5_H_INCLUDED
  20.  
  21. #include "base.h"
  22. #include <string>
  23. #include <iostream>
  24.  
  25. using namespace std;
  26.  
  27. class MD5Hash {
  28.     private:
  29.         bool done;                  // Kontrolna promenljiva koja signalizira da je doslo do kraja procesiranja MD5 hasha
  30.         bool detailed;              // Kontrolna promenljiva koja odredjuje tip prikaza na ekranu
  31.         uint1 buffer[blockSize];    // Bitovi koji nisu stali u 64bitni blok
  32.         uint32 count[2];            // 64-bitni brojac bitova
  33.         uint32 state[4];            // Podaci u obradi
  34.         uint1 digest[16];           // Rezultat
  35.  
  36.         // Logicke operacije:
  37.         static uint32 rotateLeft(uint32 x, int n);
  38.         static uint32 MD5_F(uint32 x, uint32 y, uint32 z);
  39.         static uint32 MD5_G(uint32 x, uint32 y, uint32 z);
  40.         static uint32 MD5_H(uint32 x, uint32 y, uint32 z);
  41.         static uint32 MD5_I(uint32 x, uint32 y, uint32 z);
  42.         static void MD5_FF(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac);
  43.         static void MD5_GG(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac);
  44.         static void MD5_HH(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac);
  45.         static void MD5_II(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac);
  46.         static void MD5_decode(uint32 output[], const uint1 input[], uint32 len);
  47.         static void MD5_encode(uint1 output[], const uint32 input[], uint32 len);
  48.         void m_init();
  49.         void MD5Transform(const uint1 block[blockSize]);
  50.  
  51.     public:
  52.         MD5Hash();
  53.         MD5Hash(const string& txt);
  54.         MD5Hash(const string& txt, bool val);
  55.         string MD5Input(const string str);
  56.         string MD5Input(const string str, bool val);
  57.         void MD5Process(const unsigned char *buf, uint32 length);
  58.         void MD5Process(const char *buf, uint32 length);
  59.         void setDetailed(bool);
  60.         bool getDetailed() const;
  61.         MD5Hash& MD5Compute();
  62.         string hexOutput() const;
  63.         friend ostream& operator << (ostream&, MD5Hash md5);
  64. };
  65.  
  66. #endif // MD5_H_INCLUDED
  67.  
  68.  
  69. #include "md5.h"
  70. #include "base.h"
  71. #include <cstdio>
  72.  
  73. /* Uradjeno na osnovu algoritma: http://www.ietf.org/rfc/rfc1321.txt */
  74.  
  75. //------------------------------------------------------------------------------------------------------------------------------------------
  76.  
  77. bool MD5Hash::getDetailed() const {
  78.     return detailed;
  79. }
  80.  
  81. //------------------------------------------------------------------------------------------------------------------------------------------
  82.  
  83. void MD5Hash::setDetailed(bool val) {
  84.     detailed = val;
  85. }
  86.  
  87. //------------------------------------------------------------------------------------------------------------------------------------------
  88.  
  89. MD5Hash::MD5Hash() {
  90.     m_init();
  91. }
  92.  
  93. //------------------------------------------------------------------------------------------------------------------------------------------
  94.  
  95. // Konsturktor za direktno proslijedjivanje stringa na obradu:
  96. MD5Hash::MD5Hash(const string &txt) {
  97.     m_init();
  98.     setDetailed(false);
  99.     MD5Process(txt.c_str(), txt.length());
  100.     MD5Compute();
  101. }
  102.  
  103. //------------------------------------------------------------------------------------------------------------------------------------------
  104.  
  105. // Konstruktor za direktno proslijedjivanje stringa na obradu sa dodatnom bool promenljivom koristenom za STANDARD|DETAILED output
  106. MD5Hash::MD5Hash(const string &txt, bool val) {
  107.     m_init();
  108.     setDetailed(val);
  109.     MD5Process(txt.c_str(), txt.length());
  110.     MD5Compute();
  111. }
  112.  
  113. //------------------------------------------------------------------------------------------------------------------------------------------
  114.  
  115. void MD5Hash::m_init() {
  116.     done = false;
  117.     count[0] = 0;
  118.     count[1] = 0;
  119.  
  120.     // Magicni inicijalizatori...
  121.     state[0] = 0x67452301;
  122.     state[1] = 0xefcdab89;
  123.     state[2] = 0x98badcfe;
  124.     state[3] = 0x10325476;
  125. }
  126.  
  127. //------------------------------------------------------------------------------------------------------------------------------------------
  128.  
  129. // F, G, H, I logicke operacije za MD5 hashovanje
  130. uint32 MD5Hash::MD5_F(uint32 x, uint32 y, uint32 z) {
  131.     return (x & y) | (~x & z);
  132. }
  133.  
  134. //------------------------------------------------------------------------------------------------------------------------------------------
  135.  
  136. uint32 MD5Hash::MD5_G(uint32 x, uint32 y, uint32 z) {
  137.     return (x & z) | (y & ~z);
  138. }
  139.  
  140. //------------------------------------------------------------------------------------------------------------------------------------------
  141.  
  142. uint32 MD5Hash::MD5_H(uint32 x, uint32 y, uint32 z) {
  143.     return x ^ y ^ z;
  144. }
  145.  
  146. //------------------------------------------------------------------------------------------------------------------------------------------
  147.  
  148. uint32 MD5Hash::MD5_I(uint32 x, uint32 y, uint32 z) {
  149.     return y ^ (x | ~z);
  150. }
  151.  
  152. //------------------------------------------------------------------------------------------------------------------------------------------
  153.  
  154. // Rotiramo x ulijevo za n bita
  155. uint32 MD5Hash::rotateLeft(uint32 x, int n) {
  156.     return (x << n) | (x >> (32 - n));
  157. }
  158.  
  159. //------------------------------------------------------------------------------------------------------------------------------------------
  160.  
  161. // FF, GG, HH, II transformacijske funkcije za 4 kruga MD5 hasha
  162. void MD5Hash::MD5_FF(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac) {
  163.     a = rotateLeft(a+ MD5_F(b, c, d) + x + ac, s) + b;
  164. }
  165.  
  166. //------------------------------------------------------------------------------------------------------------------------------------------
  167.  
  168. void MD5Hash::MD5_GG(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac) {
  169.     a = rotateLeft(a + MD5_G(b, c, d) + x + ac, s) + b;
  170. }
  171.  
  172. //------------------------------------------------------------------------------------------------------------------------------------------
  173.  
  174. void MD5Hash::MD5_HH(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac) {
  175.     a = rotateLeft(a + MD5_H(b, c, d) + x + ac, s) + b;
  176. }
  177.  
  178. //------------------------------------------------------------------------------------------------------------------------------------------
  179.  
  180. void MD5Hash::MD5_II(uint32 &a, uint32 b, uint32 c, uint32 d, uint32 x, uint32 s, uint32 ac) {
  181.     a = rotateLeft(a + MD5_I(b, c, d) + x + ac, s) + b;
  182. }
  183.  
  184. //------------------------------------------------------------------------------------------------------------------------------------------
  185.  
  186. // Dekodiramo unos (unsigned char) u uint4 izlaz.
  187. void MD5Hash::MD5_decode(uint32 output[], const uint1 input[], uint32 len) {
  188.     for (uint32 i = 0, j = 0; j < len; i++, j += 4)
  189.         output[i] = ((uint32)input[j]) | (((uint32)input[j+1]) << 8) | (((uint32)input[j+2]) << 16) | (((uint32)input[j+3]) << 24);
  190. }
  191.  
  192. //------------------------------------------------------------------------------------------------------------------------------------------
  193.  
  194. // Kodiramo ulaz (uint32) u unsigned char izlaz.
  195. void MD5Hash::MD5_encode(uint1 output[], const uint32 input[], uint32 len) {
  196.     for (uint32 i = 0, j = 0; j < len; i++, j += 4) {
  197.         output[j] = input[i] & 0xff;
  198.         output[j+1] = (input[i] >> 8) & 0xff;
  199.         output[j+2] = (input[i] >> 16) & 0xff;
  200.         output[j+3] = (input[i] >> 24) & 0xff;
  201.     }
  202. }
  203.  
  204. //------------------------------------------------------------------------------------------------------------------------------------------
  205.  
  206. // Primjena MD5 algoritma na blok podataka
  207. void MD5Hash::MD5Transform(const uint1 block[blockSize]) {
  208.     uint32 a = state[0];
  209.     uint32 b = state[1];
  210.     uint32 c = state[2];
  211.     uint32 d = state[3];
  212.     uint32 x[16];
  213.  
  214.     MD5_decode(x, block, blockSize);
  215.  
  216.     if (getDetailed()) {
  217.         cout << "Inicijalne vrijednosti:" << endl;
  218.         cout << "A = " << a << endl << "B = " << b << endl << "C = " << c << endl << "D = " << d << endl << "X = " << x << endl << endl;
  219.     }
  220.  
  221.     // 1. krug
  222.     MD5_FF(a, b, c, d, x[0], S11, 0xd76aa478);  // 1
  223.     MD5_FF(d, a, b, c, x[1], S12, 0xe8c7b756);
  224.     MD5_FF(c, d, a, b, x[2], S13, 0x242070db);
  225.     MD5_FF(b, c, d, a, x[3], S14, 0xc1bdceee);
  226.     MD5_FF(a, b, c, d, x[4], S11, 0xf57c0faf);
  227.     MD5_FF(d, a, b, c, x[5], S12, 0x4787c62a);
  228.     MD5_FF(c, d, a, b, x[6], S13, 0xa8304613);
  229.     MD5_FF(b, c, d, a, x[7], S14, 0xfd469501);
  230.     MD5_FF(a, b, c, d, x[8], S11, 0x698098d8);
  231.     MD5_FF(d, a, b, c, x[9], S12, 0x8b44f7af);
  232.     MD5_FF(c, d, a, b, x[10], S13, 0xffff5bb1);
  233.     MD5_FF(b, c, d, a, x[11], S14, 0x895cd7be);
  234.     MD5_FF(a, b, c, d, x[12], S11, 0x6b901122);
  235.     MD5_FF(d, a, b, c, x[13], S12, 0xfd987193);
  236.     MD5_FF(c, d, a, b, x[14], S13, 0xa679438e);
  237.     MD5_FF(b, c, d, a, x[15], S14, 0x49b40821); // 16
  238.  
  239.     if (getDetailed()) {
  240.         cout << "Prolaz 1. kruga: " << endl;
  241.         cout << "A = " << a << endl << "B = " << b << endl << "C = " << c << endl << "D = " << d << endl << "X = " << x << endl << endl;
  242.     }
  243.  
  244.     // 2. krug
  245.     MD5_GG(a, b, c, d, x[1], S21, 0xf61e2562);  // 17
  246.     MD5_GG(d, a, b, c, x[6], S22, 0xc040b340);
  247.     MD5_GG(c, d, a, b, x[11], S23, 0x265e5a51);
  248.     MD5_GG(b, c, d, a, x[0], S24, 0xe9b6c7aa);
  249.     MD5_GG(a, b, c, d, x[5], S21, 0xd62f105d);
  250.     MD5_GG(d, a, b, c, x[10], S22,  0x2441453);
  251.     MD5_GG(c, d, a, b, x[15], S23, 0xd8a1e681);
  252.     MD5_GG(b, c, d, a, x[4], S24, 0xe7d3fbc8);
  253.     MD5_GG(a, b, c, d, x[9], S21, 0x21e1cde6);
  254.     MD5_GG(d, a, b, c, x[14], S22, 0xc33707d6);
  255.     MD5_GG(c, d, a, b, x[3], S23, 0xf4d50d87);
  256.     MD5_GG(b, c, d, a, x[8], S24, 0x455a14ed);
  257.     MD5_GG(a, b, c, d, x[13], S21, 0xa9e3e905);
  258.     MD5_GG(d, a, b, c, x[2], S22, 0xfcefa3f8);
  259.     MD5_GG(c, d, a, b, x[7], S23, 0x676f02d9);
  260.     MD5_GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); // 32
  261.  
  262.     if (getDetailed()) {
  263.         cout << "Prolaz 2. kruga: " << endl;
  264.         cout << "A = " << a << endl << "B = " << b << endl << "C = " << c << endl << "D = " << d << endl << "X = " << x << endl << endl;
  265.     }
  266.  
  267.     // 3. krug
  268.     MD5_HH(a, b, c, d, x[5], S31, 0xfffa3942);  // 33
  269.     MD5_HH(d, a, b, c, x[8], S32, 0x8771f681);
  270.     MD5_HH(c, d, a, b, x[11], S33, 0x6d9d6122);
  271.     MD5_HH(b, c, d, a, x[14], S34, 0xfde5380c);
  272.     MD5_HH(a, b, c, d, x[1], S31, 0xa4beea44);
  273.     MD5_HH(d, a, b, c, x[4], S32, 0x4bdecfa9);
  274.     MD5_HH(c, d, a, b, x[7], S33, 0xf6bb4b60);
  275.     MD5_HH(b, c, d, a, x[10], S34, 0xbebfbc70);
  276.     MD5_HH(a, b, c, d, x[13], S31, 0x289b7ec6);
  277.     MD5_HH(d, a, b, c, x[0], S32, 0xeaa127fa);
  278.     MD5_HH(c, d, a, b, x[3], S33, 0xd4ef3085);
  279.     MD5_HH(b, c, d, a, x[6], S34,  0x4881d05);
  280.     MD5_HH(a, b, c, d, x[9], S31, 0xd9d4d039);
  281.     MD5_HH(d, a, b, c, x[12], S32, 0xe6db99e5);
  282.     MD5_HH(c, d, a, b, x[15], S33, 0x1fa27cf8);
  283.     MD5_HH(b, c, d, a, x[2], S34, 0xc4ac5665);  // 48
  284.  
  285.     if (getDetailed()) {
  286.         cout << "Prolaz 3. kruga: " << endl;
  287.         cout << "A = " << a << endl << "B = " << b << endl << "C = " << c << endl << "D = " << d << endl << "X = " << x << endl << endl;
  288.     }
  289.  
  290.     // 4. krug
  291.     MD5_II(a, b, c, d, x[0], S41, 0xf4292244);  // 49
  292.     MD5_II(d, a, b, c, x[7], S42, 0x432aff97);
  293.     MD5_II(c, d, a, b, x[14], S43, 0xab9423a7);
  294.     MD5_II(b, c, d, a, x[5], S44, 0xfc93a039);
  295.     MD5_II(a, b, c, d, x[12], S41, 0x655b59c3);
  296.     MD5_II(d, a, b, c, x[3], S42, 0x8f0ccc92);
  297.     MD5_II(c, d, a, b, x[10], S43, 0xffeff47d);
  298.     MD5_II(b, c, d, a, x[1], S44, 0x85845dd1);
  299.     MD5_II(a, b, c, d, x[8], S41, 0x6fa87e4f);
  300.     MD5_II(d, a, b, c, x[15], S42, 0xfe2ce6e0);
  301.     MD5_II(c, d, a, b, x[6], S43, 0xa3014314);
  302.     MD5_II(b, c, d, a, x[13], S44, 0x4e0811a1);
  303.     MD5_II(a, b, c, d, x[4], S41, 0xf7537e82);
  304.     MD5_II(d, a, b, c, x[11], S42, 0xbd3af235);
  305.     MD5_II(c, d, a, b, x[2], S43, 0x2ad7d2bb);
  306.     MD5_II(b, c, d, a, x[9], S44, 0xeb86d391);  // 64
  307.  
  308.     if (getDetailed()) {
  309.         cout << "Prolaz 4. kruga i vrijednosti prije spajanja sa inicijalnim vrijednostima:" << endl;
  310.         cout << "A = " << a << endl << "B = " << b << endl << "C = " << c << endl << "D = " << d << endl << "X = " << x << endl << endl;
  311.   }
  312.  
  313.     state[0] += a;
  314.     state[1] += b;
  315.     state[2] += c;
  316.     state[3] += d;
  317.  
  318.     if (getDetailed()) {
  319.         cout << "Vrijednosti nakon spajanja sa inicijalnim vrijednostima: " << endl;
  320.         cout << "A = " << state[0] << endl << "B = " << state[1] << endl << "C = " << state[2] << endl << "D = " << state[3] << endl;
  321.         cout << "Puni state oputput: " << state[0] << state[1] << state[2] << state[3] << endl << endl;
  322.     }
  323.  
  324.     // Resetujemo x
  325.     memset(x, 0, sizeof x);
  326. }
  327.  
  328. //------------------------------------------------------------------------------------------------------------------------------------------
  329.  
  330. // Compute funkcija koja nastavlja MD5 algoritam na drugi blok podataka
  331. void MD5Hash::MD5Process(const unsigned char input[], uint32 length) {
  332.     // Broj bitova mod 64
  333.     uint32 index = count[0] / 8 % blockSize;
  334.     uint32 i;
  335.  
  336.     if ((count[0] += (length << 3)) < (length << 3))
  337.         count[1]++;
  338.  
  339.     count[1] += (length >> 29);
  340.  
  341.     // Broj bitova koje trebamo staviti u buffer
  342.     uint32 firstpart = 64 - index;
  343.  
  344.       // Uradi transformaciju sto je vise puta moguce
  345.     if (length >= firstpart) {
  346.         // Punimo buffer
  347.         memcpy(&buffer[index], input, firstpart);
  348.         MD5Transform(buffer);
  349.  
  350.         // Transformacije dijelova od velicine bloka (64bit)
  351.         for (i = firstpart; i + blockSize <= length; i += blockSize)
  352.           MD5Transform(&input[i]);
  353.  
  354.         index = 0;
  355.     }
  356.     else
  357.         i = 0;
  358.  
  359.     // Output buffer-a
  360.     memcpy(&buffer[index], &input[i], length-i);
  361. }
  362.  
  363. //------------------------------------------------------------------------------------------------------------------------------------------
  364.  
  365. // Za svaki slucaj, opcija za signed char
  366. void MD5Hash::MD5Process(const char input[], uint32 length) {
  367.     MD5Process((const unsigned char*)input, length);
  368. }
  369.  
  370. //------------------------------------------------------------------------------------------------------------------------------------------
  371.  
  372. // Krajnji korak hashovanja:
  373. MD5Hash& MD5Hash::MD5Compute() {
  374.     static unsigned char padding[64] = {
  375.         0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  376.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  377.         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  378.     };
  379.  
  380.     if (!done) {
  381.         unsigned char bits[8];
  382.         MD5_encode(bits, count, 8);
  383.  
  384.         uint32 index = count[0] / 8 % 64;
  385.         uint32 padLen = (index < 56) ? (56 - index) : (120 - index);
  386.         MD5Process(padding, padLen);
  387.         MD5Process(bits, 8);
  388.  
  389.         MD5_encode(digest, state, 16);
  390.  
  391.         // Resetujemo buffer i brojac
  392.         memset(buffer, 0, sizeof(buffer));
  393.         memset(count, 0, sizeof(count));
  394.  
  395.         done = true;
  396.   }
  397.  
  398.     return *this;
  399. }
  400.  
  401. //------------------------------------------------------------------------------------------------------------------------------------------
  402.  
  403. // Vracamo hex vrijednost kao string:
  404. string MD5Hash::hexOutput() const {
  405.     if (!done)
  406.         return "";
  407.  
  408.     char buf[33];
  409.     for(int i=0; i<16; i++)
  410.         sprintf(buf+i*2, "%02x", digest[i]);
  411.  
  412.     buf[32] = 0;
  413.  
  414.     return string(buf);
  415. }
  416.  
  417. //------------------------------------------------------------------------------------------------------------------------------------------
  418.  
  419. // Prilagodimo operator nasim potrebama
  420. ostream& operator <<(ostream& out, MD5Hash md5) {
  421.     return out << md5.hexOutput();
  422. }
  423.  
  424. // Funkcija za unos stringa sa bool promenljivom
  425. string MD5Hash::MD5Input(const string str, bool val) {
  426.     MD5Hash md5 = MD5Hash(str, val);
  427.  
  428.     return md5.hexOutput();
  429. }
  430.  
  431. //------------------------------------------------------------------------------------------------------------------------------------------
  432.  
  433. // Funkcija za unos stringa bez bool promenljive
  434. string MD5Hash::MD5Input(const string str) {
  435.     MD5Hash md5 = MD5Hash(str);
  436.  
  437.     return md5.hexOutput();
  438. }
  439.  
  440. //------------------------------------------------------------------------------------------------------------------------------------------
  441.  
  442.  
  443. #ifndef MENU_H_INCLUDED
  444. #define MENU_H_INCLUDED
  445.  
  446. class Menu {
  447.     public:
  448.         Menu();
  449.         void initMenu();
  450. };
  451.  
  452. #endif // MENU_H_INCLUDED
  453.  
  454.  
  455. #include "menu.h"
  456. #include "config.h"
  457. #include "utils.h"
  458. #include "md5.h"
  459. #include <iostream>
  460. #include <stdlib.h>
  461. #include <ctype.h>
  462.  
  463. using namespace std;
  464.  
  465. Menu::Menu() {}
  466.  
  467. //------------------------------------------------------------------------------------------------------------------------------------------
  468.  
  469. void Menu::initMenu() {
  470.     int c = -1;         /* Korisnicki unos */
  471.     int len = 0;        /* Duzina za generisanje random stringa */
  472.     char r = '0';       /* Odgovor (response) korisnika */
  473.     string txt = "";    /* Uneseni text */
  474.     string rezim = "";  /* Rezim prikaza podataka na konzoli */
  475.  
  476.     Config cfg;         /* Instanca objekta tipa Config */
  477.     Utils u;            /* Instanca objekta tipa Utils */
  478.     MD5Hash md5;        /* Instanca objekta tipa MD5Hash */
  479.     md5.setDetailed(false); /* Pocetni rezim prikaza na konzoli je STANDARD */
  480.  
  481.     do {
  482.         rezim = (md5.getDetailed()) ? "DETALJNO" : "STANDARDNO";
  483.         cout << "Trenutni rezim prikaza: " << rezim << endl;
  484.         cout << "Meni :: MD5 - [NANSI] :: " << cfg.getAuthor() << " :: Verzija " << cfg.getStrVersion() << endl;
  485.         cout << "1. MD5 Hash - Rucni unos stringa." << endl;
  486.         cout << "2. Promjena rezima prikaza (standard <> detailed)." << endl;
  487.         cout << "3. MD5 Hash (Test primjerci)." << endl;
  488.         cout << "4. MD5 Hash od slucajno generisanog stringa." << endl;
  489.         cout << "5. Stress Test" << endl;
  490.         cout << "6. Izlaz" << endl << ">> ";
  491.         cin >> c;
  492.  
  493.         switch(c) {
  494.             case 1:
  495.                 u.cls();
  496.                 cout << "Unesite zeljeni tekst: " << endl << ">> ";
  497.                 cin >> txt;
  498.                 cout << "MD5 Hash od '" << txt << "' stringa je: " << md5.MD5Input(txt, md5.getDetailed()) << endl << endl << endl;
  499.                 break;
  500.  
  501.             case 2:
  502.                 u.cls();
  503.                 md5.setDetailed(!md5.getDetailed());
  504.                 cout << "Rezim prikaza informacija je uspjesno promenjen!" << endl << endl;
  505.                 break;
  506.  
  507.             case 3:
  508.                 u.cls();
  509.                 cout << "MD5 Hash od 'test' stringa: " << md5.MD5Input("test", md5.getDetailed()) << endl;
  510.                 cout << "MD5 Hash od 'ftn' stringa: " << md5.MD5Input("ftn", md5.getDetailed()) << endl;
  511.                 cout << "MD5 Hash od 'goran' stringa: " << md5.MD5Input("goran", md5.getDetailed()) << endl;
  512.                 cout << "Svi navedeni primjeri su testirani sa PHP md5() funkcijom i daju iste rezultate." << endl << endl;
  513.                 break;
  514.  
  515.             case 4:
  516.                 u.cls();
  517.                 do {
  518.                     cout << "Unesite zeljenu duzinu stringa:" << endl << ">> ";
  519.                     cin >> len;
  520.                 } while ((len <= 0) && (!isdigit(len)));
  521.                 txt = u.generateRandomString(len);
  522.                 cout << "MD5 Hash9 za slucajno generisani string '" << txt << "' je: " << endl << md5.MD5Input(txt, md5.getDetailed()) << endl << endl;
  523.                 break;
  524.  
  525.  
  526.             case 5:
  527.                 for (int i = 0; i<= 2000; i++) {
  528.                     cout << md5.MD5Input(u.generateRandomString(i)) << endl;
  529.                 }
  530.                 break;
  531.  
  532.             case 6:
  533.                 do {
  534.                     cout << "\tDa li sigurno zelite da izadjete?? [y/n]" << endl << ">> ";
  535.                     cin >> r;
  536.                 } while (r != 'y' && r != 'n');
  537.  
  538.                 if (r == 'y')
  539.                     exit(EXIT_SUCCESS);
  540.                 else {
  541.                     u.cls();
  542.                     initMenu();
  543.                     break;
  544.                 }
  545.  
  546.             default:
  547.                 u.cls();
  548.                 cout << "Nepoznat unos!" << endl << endl;
  549.         }
  550.     } while( ((c < 1) || (c > 6)) && cin.good());
  551. }
  552.  
  553. //------------------------------------------------------------------------------------------------------------------------------------------
  554.  
  555. #ifndef CONFIG_H_INCLUDED
  556. #define CONFIG_H_INCLUDED
  557.  
  558. #include <string>
  559. using namespace std;
  560.  
  561. class Config {
  562.     private:
  563.         string author;
  564.         string s_version;
  565.         int i_version;
  566.  
  567.     public:
  568.         Config();
  569.         string getAuthor() const;
  570.         string getStrVersion() const;
  571.         int getIntVersion() const;
  572.  
  573. };
  574.  
  575. #endif // CONFIG_H_INCLUDED
  576.  
  577. #include "config.h"
  578. #include "string.h"
  579.  
  580. Config::Config() {
  581.     author = "Goran Todorovic RA 170/2011";
  582.     s_version = "0.0.1";
  583.     i_version = 001;
  584. }
  585.  
  586. string Config::getAuthor() const {
  587.     return author;
  588. }
  589.  
  590. string Config::getStrVersion() const {
  591.     return s_version;
  592. }
  593.  
  594. int Config::getIntVersion() const {
  595.     return i_version;
  596. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement