A complete implementation of TEA (Tiny Encryption Algorithm) encryption and decryption for files.

- TEA Encryption/Decryption: Full implementation of the Tiny Encryption Algorithm
- File-based Operations: Encrypt and decrypt entire files
- Custom Key Support: Use your own key files (converted to 128-bit hash)
- Block Processing: Handles files of any size by processing in 8-byte blocks
- Automatic Padding: Handles files that aren't multiples of 8 bytes
- SHA-256 Key Hashing: Converts any key file to a 128-bit hash for consistent key size
The implementation follows the standard TEA algorithm:
- Key Processing: Converts input key to SHA-256 hash and uses first 16 bytes
- Block Processing: Processes data in 8-byte blocks
- Encryption: 32 rounds of TEA encryption with delta constant
- Padding: Automatically adds null bytes to make data length multiple of 8
- Decryption: 32 rounds of TEA decryption with automatic padding removal
- TEA Algorithm: Complete implementation of Tiny Encryption Algorithm
- Key Hashing: SHA-256 hashing for consistent 128-bit keys
- Block Processing: 8-byte block encryption/decryption
- Padding Management: Automatic padding during encryption and removal during decryption
# Encrypt a file
go run main.go -e file=<file to encrypt> key=<keyfile>
# Decrypt a file
go run main.go -d file=<file to decrypt> key=<keyfile>
-e
: Encrypt the specified file-d
: Decrypt the specified filefile=<path>
: Path to the input filekey=<path>
: Path to the key file
The key file can contain any content. The system will:
- Read the entire key file
- Generate a SHA-256 hash of the content
- Use the first 16 bytes of the hash as the TEA key
Example of creating a key file:
# Create a key file with any content
echo "MySecretKey12345" > mykey.txt
# Or use a random key
openssl rand -base64 32 > mykey.txt
- Encryption: Overwrites the input file with encrypted content
- Decryption: Overwrites the input file with decrypted content
The implementation includes all standard TEA operations:
- Key Setup: 4 uint32 values derived from 16-byte key
- Block Processing: 8-byte blocks with 32 rounds
- Delta Constant: Uses 0x9E3779B9 as the delta value
- Padding: Null byte padding for non-8-byte aligned data
- Complete TEA Implementation: Full encryption and decryption
- SHA-256 Key Hashing: Consistent 128-bit key generation
- Automatic Padding: Handles files of any size
- Error Handling: Input validation and error reporting
- Overflow Protection: Proper handling of large calculations
- Uses TEA algorithm with 32 rounds
- SHA-256 key hashing for consistent key size
- Processes data in 8-byte blocks
- Automatic padding management
# Build the application
go build -o file-encryptor
# Run with arguments
./file-encryptor -e file=document.txt key=secret.key
# 1. Create a test file
echo "Hello, this is a secret message!" > secret.txt
# 2. Create a key file
echo "MySecretKey12345" > mykey.txt
# 3. Encrypt the file
go run main.go -e file=secret.txt key=mykey.txt
# 4. Verify encryption (file should be unreadable)
cat secret.txt
# 5. Decrypt the file
go run main.go -d file=secret.txt key=mykey.txt
# 6. Verify decryption
cat secret.txt
The codebase is organized into several modules:
tea/encrypt.go
: TEA encryption implementationtea/decrypt.go
: TEA decryption implementationcmd/args.go
: Command-line argument parsingcmd/io.go
: File I/O operationsmain.go
: Application entry point and workflow
All cryptographic operations are implemented from scratch, ensuring no external cryptographic dependencies beyond Go's standard library.
file-encryptor/
├── main.go # Main application entry point
├── tea/
│ ├── encrypt.go # TEA encryption implementation
│ └── decrypt.go # TEA decryption implementation
├── cmd/
│ ├── args.go # Command-line argument parsing
│ └── reader.go # File I/O operations
├── go.mod # Go module definition
└── readme.md # This file