====================================================
  PASSWORD MANAGER - Documentation
====================================================


1. SUPPORTED FUNCTIONALITY
---------------------------
The application is a command-line password manager written in C
that supports the following features:

  - Add a credential record
      The user enters a service name, username, and password.
      All three fields are encoded before being written to file.
      Empty fields are rejected.

  - List all saved entries
      Reads every record from passwords.txt, decodes them,
      and prints them to the screen in a numbered list.

  - Search by service name
      The user types a service name. The program scans all
      records and prints every entry whose service field
      matches exactly.

  - Delete an entry by service name
      The user types a service name. All records with that
      name are removed. The remaining records are written
      back to the file.

  - Persistent file storage
      All data is saved in passwords.txt so it is available
      across program runs. The file is created automatically
      on the first add.

  - Encoded storage
      Passwords, usernames, and service names are never stored
      as plain text. A Caesar shift of 7 is applied to every
      character before writing to the file.


2. HOW THE SOLUTION IS ORGANIZED
----------------------------------

Source file: password_manager.c

  Struct
  ------
  Entry
      Stores one credential record with three fields:
      service[60], user[60], pass[60].

  Constants
  ---------
  DATA_FILE     the storage file name (passwords.txt)
  SHIFT         the encoding shift value (7)
  MAX_RECORDS   maximum entries that can be loaded at once (200)
  SERVICE_LEN, USER_LEN, PASS_LEN   buffer sizes for each field

  Helper functions
  ----------------
  flush_input()
      After reading a number with scanf, leftover characters
      stay in the input buffer. This function discards them
      so the next keyboard read works correctly.

  read_line(buf, limit)
      Reads one line of keyboard input using fgets and removes
      the newline character at the end.

  encode(s)
      Loops through a string and adds 7 to every character's
      ASCII value, making it unreadable in the file.

  decode(s)
      Loops through a string and subtracts 7 from every
      character's ASCII value, restoring the original text.

  print_divider() / print_entry(e)
      Display helpers that print a credential record inside
      a formatted box.

  File I/O functions
  ------------------
  load_all(entries, max)
      Opens passwords.txt and reads every entry into an array
      of Entry structs. Each entry occupies three consecutive
      lines in the file (service, username, password). fscanf
      reads one line at a time using the format %59[^\n]\n,
      which reads up to 59 characters until the end of the line.
      Each field is decoded after reading so it is readable
      while the program is running. Returns the number of
      entries loaded.

  save_all(entries, count)
      Opens passwords.txt in write mode (overwriting it) and
      writes every entry in the array back to the file encoded.
      This is used by delete_entry: after removing the unwanted
      entries from the array, the remaining ones are written
      back. Encoding before writing ensures the file never
      contains plain text. A copy of each entry is used so the
      version in memory stays decoded.

  Menu functions
  --------------
  add_entry()
      Opens passwords.txt in append mode, reads the three
      fields from the user, rejects blank fields, encodes
      all three, and writes each field on its own line.

  list_entries()
      Calls load_all to get all records, then prints each one
      using print_entry.

  search_entry()
      Calls load_all, then loops through every record comparing
      the service field to the search query using strcmp.
      Prints every match found.

  delete_entry()
      Calls load_all to get all records. Loops through them and
      separates matching entries (to be deleted) from non-matching
      ones (to be kept). Calls save_all with only the kept entries
      to overwrite the file.

  main()
      Runs an infinite loop that prints the menu, reads an integer
      choice with scanf, and calls the matching function.
      Exits on choice 5.

  Encoding algorithm
  ------------------
  Every character in a string has 7 added to its ASCII value
  before being written to the file. To read it back, 7 is
  subtracted. This means no field in passwords.txt is ever
  stored as readable text. The shift of 7 applies to service
  name, username, and password equally.

  Storage format (three lines per entry)
  ---------------------------------------
  Each entry is stored as three consecutive lines:

      encodedService
      encodedUser
      encodedPass

  No separator character is used. Each field occupies its own
  line so there is no risk of an encoded character accidentally
  matching a separator. For example, with a shift of 7 the
  letter 'u' (ASCII 117) encodes to '|' (ASCII 124). If a
  pipe were used as a separator, a password containing 'u'
  would corrupt the file format. The three-line approach
  avoids this problem entirely.


3. TESTING
-----------

Testing approach
----------------
The application was tested manually by running it, entering
inputs for each feature, and checking that the printed output
and contents of passwords.txt matched what was expected.

Test cases
----------

Test 1: Add a single entry
  Steps:    Choose 1. Enter service: gmail, username: alice@gmail.com,
            password: pass123
  Expected: Prints "Entry saved." passwords.txt is created with
            three lines of encoded text (one per field).
  Result:   PASS

Test 2: Add multiple entries then list all
  Steps:    Add a second entry: github / alice / abc456. Choose 2.
  Expected: Both entries shown decoded in the correct order.
  Result:   PASS

Test 3: Search for an existing service
  Steps:    Choose 3. Enter: gmail
  Expected: Only the gmail entry is shown. github is not shown.
  Result:   PASS

Test 4: Search for a service that does not exist
  Steps:    Choose 3. Enter: facebook
  Expected: Prints "No entries found for facebook."
  Result:   PASS

Test 5: Delete an existing entry
  Steps:    Choose 4. Enter: gmail
  Expected: Prints "Deleted 1 entry/entries for gmail."
            Listing afterwards shows only the github entry.
  Result:   PASS

Test 6: Delete a service that does not exist
  Steps:    Choose 4. Enter: twitter
  Expected: Prints "No entries found for twitter."
            passwords.txt is unchanged.
  Result:   PASS

Test 7: Add two entries with the same service name then delete
  Steps:    Add two entries both with service: gmail.
            Choose 4, enter: gmail
  Expected: Prints "Deleted 2 entry/entries for gmail."
            List shows no gmail entries remaining.
  Result:   PASS

Test 8: List when no entries have been saved
  Steps:    Delete passwords.txt, then choose 2.
  Expected: Prints "No entries stored yet." without crashing.
  Result:   PASS

Test 9: Enter a non-numeric menu choice
  Steps:    Type: abc at the menu prompt.
  Expected: Prints "Please enter a number." and shows menu again.
  Result:   PASS

Test 10: Add entry with an empty field
  Steps:    Choose 1. Press Enter immediately for service name.
  Expected: Prints "Fields cannot be empty." Nothing written to file.
  Result:   PASS

Test 11: passwords.txt does not contain plain text
  Steps:    Add an entry with password: hello. Open passwords.txt.
  Expected: The word "hello" does not appear anywhere in the file.
            All fields appear as garbled characters.
  Result:   PASS
