Skip to content

Conversation

@Shewale41
Copy link

# ✨ Add One-Time Pad Cipher Implementation  
Fixes #6941  

This PR adds a simple implementation of the **One-Time Pad Cipher** in Java under the `ciphers` package. It demonstrates XOR-based encryption and decryption using a random key of equal length to the plaintext.  

### 🧩 File Added  
`src/main/java/com/thealgorithms/ciphers/OneTimePadCipher.java`  

### ⚙️ Implementation Details  
- Uses `SecureRandom` for key generation  
- Encrypts and decrypts using the same XOR logic  
- Includes a small demo in the `main()` method  
- Time Complexity: **O(n)**  
- Space Complexity: **O(n)**  

### 🧪 Example Usage  
**Input:**  

Message: HELLO WORLD
Key: 4@_Zb1+|hG#

**Output:**  

Encrypted: �$%&!
Decrypted: HELLO WORLD


### 🧠 Summary  
This algorithm showcases the concept of perfect secrecy through XOR operation, where encryption and decryption use the same key. It’s lightweight, symmetric, and educational for understanding cryptographic basics.  

### 🧑‍💻 Author  
[@Shewale41](https://github.com/Shewale41)  

@Shewale41 Shewale41 changed the title Add One-Time Pad Cipher implementation in Java Added One-Time Pad Cipher implementation in Java #6941 Oct 27, 2025
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 0% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.19%. Comparing base (21eff8a) to head (a179b5b).

Files with missing lines Patch % Lines
...va/com/thealgorithms/ciphers/OneTimePadCipher.java 0.00% 22 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6965      +/-   ##
============================================
- Coverage     78.26%   78.19%   -0.08%     
- Complexity     6573     6574       +1     
============================================
  Files           743      744       +1     
  Lines         21895    21917      +22     
  Branches       4288     4290       +2     
============================================
+ Hits          17137    17138       +1     
- Misses         4074     4096      +22     
+ Partials        684      683       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Shewale41 Shewale41 closed this Oct 27, 2025
@Shewale41 Shewale41 deleted the add-one-time-pad-cipher branch October 27, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants