c++ - Swap function based on ai+b mod n -
i need swap function swap based on results after computing ai+b mod n
for example have text : "test"
, want swap based on ai+b mod n
result ai+b mod n
2, 4, 1, 3 ie text after swap "etts" letter @ first position @ position 3, position 2 position 1, position 3 4 , 4 2.
the following code generate values ax+b mod n
, need on how swap words in file. in advance.
int main () { cout << "enter values of , b." << endl; cin >> >> b; cout << "enter input file name." << endl; cin >> inputfile; file * pfile; pfile = fopen (inputfile, "rb"); if (pfile == null) perror ("error opening file"); else { fseek (pfile, 0, seek_end); // non-portable sizeoffile = ftell (pfile); cout << sizeoffile << "\n"; fclose (pfile); } n = sizeoffile / 32; cout << n << endl; (i = 1; <= n; i++) { int message1 = ((a * + b) % n); int c = message1; cout << c << endl; } return c; }
create second string, same length first, , copy (ai+b)'th character of first string i'th position of output.
keep in mind c++ starts counting @ 0.
Comments
Post a Comment