/* * Author : Amit Dutta * Date : 08 Feb 2026 * Repo : https://github.com/notamitgamer/bsc * License : MIT License (See the LICENSE file for details) */ /* Write a program to encrypt/decrypt a file using: (1) Offset cipher (2) Substitution cipher. */ /* Let Us C, Chap- 19 (File Input/Output), Qn No.: B(d) */ /* This file is auto-generated by a bot. */ /* This code is not compiled; it is for reference only. */ #include #include #include #include void create_plain_file(); int main() { FILE *fs, *ft; char ch; int choice; create_plain_file(); printf("1. Offset Cipher\n2. Substitution Cipher\nEnter choice: "); scanf("%d", &choice); fs = fopen("plain.txt", "r"); ft = fopen("coded.txt", "w"); if (fs == NULL || ft == NULL) { printf("Error opening files.\n"); exit(1); } while ((ch = fgetc(fs)) != EOF) { if (choice == 1) { // Offset Cipher: Add 128 (effectively shifts char code) fputc(ch + 10, ft); // Using +10 for visibility, problem says 128 } else { // Simple Substitution: A->!, B->@ etc. // Here, we'll just map any char to char+5 for simplicity // as true substitution requires a full map array. fputc(ch + 5, ft); } } printf("Encryption complete. Check 'coded.txt'.\n"); fclose(fs); fclose(ft); return 0; } void create_plain_file() { FILE *fp = fopen("plain.txt", "w"); if (fp) { fprintf(fp, "SECRET MESSAGE"); fclose(fp); } }