Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Below is a rewritten version that outputs the same numbers pretty much
- but without relying on ADR_148D[Y]
- (There's another version written to act more like 65c815 asm)
- */
- #include <iostream>
- #include <ctime> // For the time function
- using namespace std;
- // Process setting/clearing the carry flag
- void Process_C(int &A, bool &PF_C)
- {
- PF_C = false;
- while(A < 0 || A > 255){PF_C = true; A &= 0xFF;}
- }
- //[0, ((256^bytes)-1)]
- unsigned long int GetRand(int bytes, int &ADR_148B, int &ADR_148C, bool &PF_C)
- {
- unsigned long int out = 0;
- do
- {
- int temp = ADR_148B;
- temp = temp << 2;
- Process_C(temp, PF_C);
- PF_C = true;
- temp += ADR_148B + PF_C; //PF_C = 1; always
- Process_C(temp, PF_C);
- ADR_148B = temp;
- ADR_148C = ADR_148C << 1;
- Process_C(ADR_148C, PF_C);
- if ( (!PF_C) ^ (0x20 & ADR_148C) )
- {
- if (++ADR_148C > 255)
- {
- ADR_148C = 0;
- }
- }
- temp = ADR_148C^ADR_148B;
- out |= temp;
- while(bytes > 1 && (out & 0xFF))
- {
- out = out << 8;
- }
- bytes--;
- }
- while(bytes > 0);
- return out;
- }
- int main()
- {
- // The Carry Processor Flag
- bool PF_C;
- int ADR_148B;
- int ADR_148C;
- ADR_148B = (ADR_148B + time(0)) & 0xFF;
- ADR_148C = (ADR_148C + time(0)) & 0xFF;
- unsigned long int temp;
- for(int i = 1; i <= 5; i++)
- {
- for(int i = 1; i <= 4; i++)
- {
- temp = GetRand(i, ADR_148B, ADR_148C, PF_C); // i bytes of entropy from 1-4 (8-bit, 32-bit, 512-bit, 4096-bit)
- cout << hex << "0x" << temp << " (" << dec << temp << ") - ";
- }
- cout << "\n\n";
- //temp = GetRand(2, ADR_148B, ADR_148C, PF_C); 2 bytes of entropy
- //cout << "\n" << hex << "0x" << temp << " (" << dec << temp << ")\n\n";
- }
- long double avg = 0;
- int cnt = 0;
- for(int i = 1; i <= 500; i++)
- {
- for(int i = 1; i <= 6; i++)
- {
- temp = GetRand(1, ADR_148B, ADR_148C, PF_C);
- avg += temp;
- cnt++;
- // Uncommenting these will output all the hex in a similar manner to the loop above
- //cout << hex << "0x" << temp << " (" << dec << temp << ") - ";
- }
- //cout << "\n";
- }
- cout << "The average of " << cnt << " random values was: " << avg/cnt << " for 1 byte of entropy (0-255).";
- cout << "\nWhich is a difference of " << (avg/cnt)-127.5 << "\nFrom the expected average of 127.5";
- /*
- 2 bytes: 32767.5
- 3 bytes: 8388607.5
- 4 bytes: 2147483647.5
- */
- cout << "\n\nPress Enter to Exit. ";
- cin.ignore();
- //cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement