Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdio.h>
- int main(int argc, char *argv[]) {
- int g[8][16] = { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1 },
- { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ,1 ,1, 1 },
- { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0 },
- { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1 },
- { 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1 },
- { 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0 } };
- FILE *ulazna, *izlazna;
- int i=0, k;
- char poc[100];
- char *p;
- gets(poc);
- for (p = strtok(poc, " "); p; p = strtok(NULL, " ")) {
- if (i == 0) {
- printf("%s\n", p);
- ulazna = fopen(p, "r");
- if (ulazna == NULL) {
- printf("Greska prilikom otvaranja datoteke.");
- return 0;
- }
- }
- else {
- printf("%s\n", p);
- izlazna = fopen(p, "wb");
- if (izlazna == NULL) {
- printf("Greška prilikom otvaranja datoteke.");
- return 0;
- }
- }
- i++;
- }
- int c;
- while ((c = fgetc(ulazna)) != EOF) //ciranje znak po znak
- {
- int m = ((int)c);
- int result[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- int polje[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
- int z = 7;
- int pom = 0;
- short znak = 0;
- //binarni zapis procitanog znaka sa ulaza
- while (m != 0) {
- pom = m % 2;
- m /= 2;
- polje[z] = ((char)pom);
- z--;
- }
- //mnozenje matrice i ulaznog znaka
- for (int i = 0; i < 16; i++)
- {
- for (int k = 0; k < 8; k++)
- {
- result[i] ^= (polje[k] * g[k][i]);
- }
- }
- for (int i = 0; i < 16; i++) {
- znak = (znak << 1);
- znak += result[i];
- }
- fwrite(&znak, sizeof(short), 1, izlazna);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement