Guest User

Untitled

a guest
Jan 21st, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <QCoreApplication>
  2. #include <QDebug>
  3.  
  4. #include <QByteArray>
  5. #include <QCryptographicHash>
  6.  
  7. QByteArray sha256(QByteArray in)
  8. {
  9. QCryptographicHash hash (QCryptographicHash::Sha256);
  10.  
  11. hash.addData(in);
  12.  
  13. QByteArray res1 = hash.result();
  14.  
  15. return res1;
  16. }
  17.  
  18. QByteArray sha256d(QByteArray in)
  19. {
  20. QCryptographicHash hash (QCryptographicHash::Sha256);
  21.  
  22. hash.addData(in);
  23.  
  24. QByteArray res1 = hash.result();
  25. hash.reset();
  26. hash.addData(res1);
  27.  
  28. return hash.result();
  29. }
  30.  
  31. QByteArray reverse_hash (QByteArray in)
  32. {
  33. QByteArray res;
  34. if (in.length() != 32) return QByteArray::fromHex("");
  35.  
  36. for (int i = 0; i < 32; ++i)
  37. {
  38. res.append(in[31 - i]);
  39. }
  40.  
  41. return res;
  42. }
  43.  
  44. int main(int argc, char *argv[])
  45. {
  46. QCoreApplication app(argc, argv);
  47.  
  48. {//BTC block 70003
  49. QByteArray a = QByteArray::fromHex("6a7df1c030c1ad32cbaa21aa491194ac3b945f0dbe61dff2ef95f9c62f5650ee");
  50. QByteArray b = QByteArray::fromHex("8e32e4a5ba602390a1e9cc019bd3a49a68e2116a56310e12c5bbeab142a67720");
  51. a = reverse_hash(a);
  52. b = reverse_hash(b);
  53.  
  54. QByteArray c = a + b;
  55. QByteArray m = sha256d( c );
  56. m = reverse_hash(m);
  57.  
  58. qDebug() << m.toHex();
  59. }
  60.  
  61.  
  62. {//VTC block 800019
  63. QByteArray a = QByteArray::fromHex("32e60eb21632597c1c1545c63fae57df8d4455648b7d97150b7dcee706749588");
  64. QByteArray b = QByteArray::fromHex("1deed158ada568b9b193473095c8eb2cef2cffe60ccce15c3c82f599a09767a8");
  65. a = reverse_hash(a);
  66. b = reverse_hash(b);
  67.  
  68. qDebug() << a.toHex();
  69. qDebug() << b.toHex();
  70.  
  71. QByteArray c = a + b;
  72. QByteArray m = sha256d( c );
  73. m = reverse_hash(m);
  74.  
  75. qDebug() << m.toHex();
  76. }
  77.  
  78.  
  79. return 0;
  80. }
Add Comment
Please, Sign In to add comment