Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void encrypt(char* msg, size_t msg_size, char* key, size_t key_size)
- {
- size_t key_index = 0;
- for (size_t i = 0; i < msg_size; i++)
- {
- msg[i] ^= key[key_index];
- ++key_index;
- if (key_index > key_size)
- key_index = 0;
- }
- }
- void encrypt_file(char* in_name, char* out_name, char* key, size_t key_size)
- {
- char buf[1024];
- size_t nread;
- FILE* in_file = fopen(in_name, "rb");
- FILE* out_file = fopen(out_name, "wb");
- int count = 0;
- while ((nread = fread(buf, 1, sizeof(buf), in_file)) > 0)
- {
- count += nread;
- printf("Bytes read: %i\nTotal: %i\n\n", nread, count);
- encrypt(buf, nread, key, key_size);
- fwrite(buf, 1, nread, out_file);
- }
- if (ferror(in_file) || ferror(out_file))
- {
- printf("Some error occured lol.\n");
- }
- fclose(in_file);
- fclose(out_file);
- }
- int main()
- {
- char key[] = "KsAdda2223132dfSDASDSSDASDWDsfsad3A";
- size_t key_size = strlen(key);
- encrypt_file("lifesaver2.jpg", "encrypted.jpg", key, key_size);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement