/** * @Comment: WSU - Fall 06 - CS 3830-0 * @Title: prj4c.c - Project 4 * @Author: Vincenzo Maggio */ #include #include #include #include #include int main( void) { const char *stringa = "Certain cryptographic devices and technical data regarding them are deemed to be defense articles (i.e., inherently military in character) and are subject to Federal government export controls."; const char *stringb = "Telling women they can't do well in math may turn out be a self-fulfilling statement. In tests in Canada, women who were told that men and women do math equally well did much better than those who were told there is a genetic difference in math ability."; char stringr[260]; char cse[260]; char cArray[2080]; unsigned long long primer = 0, LLResult = 0; unsigned long lResult = 0; int N, j, onesCounter, iStrLen; int p = 1783, q = 1979, s = 31571; char cPrevValue, cRes, *cp, *cs, *ca, *ce; system("cls"); system("color f0"); gotoxy( 29, 2); printf("CS 3830 - Project 4 part c\n\n"); printf(" Generating...\n\n"); memset( cArray, 0, 2080); memset( stringr, 0, 260); memset( cse, 0, 260); /* generation */ N = p * q, primer = ( s * s) % N; for ( j = 0; j < 2080; j++ ) { LLResult = primer % N, primer = LLResult * LLResult; onesCounter = 0; while ( LLResult ) { if ( LLResult % 2) ++onesCounter; LLResult = LLResult >> 1; } if ( onesCounter % 2 ) cArray[j] = 1; else cArray[j] = 0; } /* string #1 */ cp = stringa; cs = stringr; ce = cse; iStrLen = strlen( stringa); while ( iStrLen ) { cRes = 0; if ( *(ca + 1)) cRes += 64; if ( *(ca + 2)) cRes += 32; if ( *(ca + 3)) cRes += 16; if ( *(ca + 4)) cRes += 8; if ( *(ca + 5)) cRes += 4; if ( *(ca + 6)) cRes += 2; if ( *(ca + 7)) cRes += 1; *ce = cRes; *cs = *cp ^ cRes; ca += 8, --iStrLen, ++cs, ++cp, ++ce; } iStrLen = strlen( stringa); for ( j = 0; j < iStrLen; j++) printf( "%02x ", stringr[j]); printf("\n\n"); iStrLen = strlen( stringa); for ( j = 0; j < iStrLen; j++) printf("%c", stringr[j] ^ cse[j]); printf("\n\n\n "); system("pause"); printf("\n\n "); printf(" Project 4 program 3 part b\n\n\n"); /* ********************************************************************* */ /* string #2 */ memset( cArray, 0, 2080); p = 2347, q = 5927, s = 86591; /* generation */ N = p * q, primer = ( s * s) % N; for ( j = 0; j < 2080; j++ ) { LLResult = primer % N, primer = LLResult * LLResult; onesCounter = 0; while ( LLResult ) { if ( LLResult % 2) ++onesCounter; LLResult = LLResult >> 1; } if ( onesCounter % 2 ) cArray[j] = 1; else cArray[j] = 0; } memset( stringr, 0, 260); memset( cse, 0, 260); cp = stringb; cs = stringr; ce = cse; iStrLen = strlen( stringb); while ( iStrLen ) { cRes = 0; if ( *(ca + 1)) cRes += 64; if ( *(ca + 2)) cRes += 32; if ( *(ca + 3)) cRes += 16; if ( *(ca + 4)) cRes += 8; if ( *(ca + 5)) cRes += 4; if ( *(ca + 6)) cRes += 2; if ( *(ca + 7)) cRes += 1; *ce = cRes; *cs = *cp ^ cRes; ca += 8, --iStrLen, ++cs, ++cp, ++ce; } iStrLen = strlen( stringb); for ( j = 0; j < iStrLen; j++) printf( "%02x ", stringr[j]); printf("\n\n"); iStrLen = strlen( stringb); for ( j = 0; j < iStrLen; j++) printf("%c", stringr[j] ^ cse[j]); printf("\n\n\n "); system("pause"); system("color 0f"); return 0; } /* niam */