Skip to content

[R45-T017] Publish runnable worked example and tests for AESEncryption - #57

Open
shyamlibakale1001-alt wants to merge 1 commit into
S-AI-Projects:masterfrom
shyamlibakale1001-alt:student/e26b07f0813/R45-T017
Open

shyamlibakale1001-alt wants to merge 1 commit into
S-AI-Projects:masterfrom
shyamlibakale1001-alt:student/e26b07f0813/R45-T017

Conversation

@shyamlibakale1001-alt

Copy link
Copy Markdown

Description

Enhances the class Javadoc of src/main/java/com/thealgorithms/ciphers/AESEncryption.java with an executable worked example, intermediate state sizes, the decisive aesCipher.getIV() state transition, and expected console output; adds AESEncryptionExampleTest.java executing that example and verifying smallest and ordinary inputs; and adds work/R45-T017/check.py to run and record the checks. All existing behavior and public interfaces are preserved.

Related Issue

Fixes: #17

Type of Change

  • Bug Fix
  • New Feature
  • UI/UX Improvement
  • Performance Improvement
  • Tests
  • Documentation
  • Refactoring / Maintenance
  • CI/CD

Changes Made

  • Updated Javadoc in src/main/java/com/thealgorithms/ciphers/AESEncryption.java (lines 20–36) with the runnable worked example (getSecretEncryptionKey() → encryptText("Hello World", secKey) → decryptText(cipherText, secKey)), the decisive aesCipher.getIV() state transition (12-byte GCM IV + 128-bit authentication tag), and expected main output. No executable code or public API was altered.
  • Added src/test/java/com/thealgorithms/ciphers/AESEncryptionExampleTest.java with 3 test methods (9 logged steps):
    • Smallest valid inputs ("" → 16-byte GCM tag / 32 hex chars; "A" → 17 bytes / 34 hex chars) with round-trip verification and precondition line citations.
    • Ordinary input ("Hello World", 11 bytes = 48656C6C6F20576F726C64 in hex) with a fixed 128-bit SecretKeySpec (00000000000000000000000000000000), verifying 27-byte / 54-hex-char ciphertext+tag output, round-trip recovery, and the AEADBadTagException caused when a subsequent encryptText call overwrites aesCipher's IV.
    • Executes AESEncryption.main(new String[0]) and asserts all 4 displayed stdout lines (Original Text:Hello World, 32-char hex key, 54-char hex ciphertext, Decryption successful. Decrypted text matches original: true).
  • Added work/R45-T017/check.py (with evidence files in work/R45-T017/), running mvn test for AESEncryptionExampleTest, enforcing a nonzero test count, saving comparisons.txt, result.txt, mvn_output.txt, and tool_versions.txt, and exiting non-zero on failure.

Screenshots / Recordings

Not applicable (no UI changes).

Testing

Command: python3 work/R45-T017/check.py
(runs mvn -B test -Dtest=AESEncryptionExampleTest -Dsurefire.failIfNoSpecifiedTests=false)

Result: tests=3 failures/errors=0 skipped=0 records=9 mvn_exit=0, status=PASS

Existing suite: mvn -B test -Dtest=AESEncryptionTest -Dsurefire.failIfNoSpecifiedTests=false → Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 (BUILD SUCCESS).

Negative check: temporarily changing aesKeyGenerator.init(128); to 256 on line 71 caused python3 work/R45-T017/check.py to print status=FAIL (tests=3 failures/errors=2 skipped=0 mvn_exit=1) and exit non-zero; reverted and re-verified.

Style: mvn -B checkstyle:check reports 0 Checkstyle violations (BUILD SUCCESS).

Tool versions and check records are saved in work/R45-T017/tool_versions.txt and work/R45-T017/comparisons.txt.

Checklist

  • I have tested my changes locally.
  • I have added or updated tests, if needed.
  • I have updated documentation, if needed.
  • I have followed the project's coding guidelines.
  • I have run the relevant tests and checks.
  • I have addressed previous review feedback, if applicable.

Additional Notes

  • Decisive state transition: encryptText assigns a newly initialized AES/GCM/NoPadding Cipher (with a fresh random 12-byte IV) to the static aesCipher field, and decryptText depends on aesCipher.getIV() from that most recent encryption call.

  • The work/R45-T017/ evidence folder is for coursework review only and should not go into any later upstream PR.

  • I have read CONTRIBUTING.md.

  • This pull request is all my own work -- I have not plagiarized it.

  • All filenames are in PascalCase.

  • All functions and variable names follow Java naming conventions.

  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.

  • All new algorithms include a corresponding test class that validates their functionality.

  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant