-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_encrypt_decrypt.py
More file actions
113 lines (88 loc) · 3.18 KB
/
test_encrypt_decrypt.py
File metadata and controls
113 lines (88 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
"""Test script to verify encryption and decryption work correctly"""
from payload_encrypter import encrypt_bubble_payload
from payload_decrypter import decrypt_bubble_payload
import json
def test_encryption_decryption():
"""Test that encryption and decryption are reversible"""
print("=" * 80)
print("🔬 Testing Encryption & Decryption")
print("=" * 80)
# Test data
appname = "your_app_name"
test_payload = {
"appname": "your_app_name",
"app_version": "live",
"test_data": "This is a test payload",
"number": 12345,
"nested": {
"key": "value",
"array": [1, 2, 3, 4, 5]
}
}
print(f"\n📱 AppName: {appname}")
print(f"\n📄 Original Payload:")
print(json.dumps(test_payload, indent=2, ensure_ascii=False))
# Step 1: Encrypt
print("\n" + "-" * 80)
print("🔒 Step 1: Encrypting...")
print("-" * 80)
encrypted = encrypt_bubble_payload(appname, test_payload)
print(f"✅ Timestamp: {encrypted['timestamp']}")
print(f"✅ IV (hex): {encrypted['iv']}")
print(f"\n🔑 Encrypted x (IV): {encrypted['x'][:50]}...")
print(f"🔑 Encrypted y (timestamp): {encrypted['y']}")
print(f"🔑 Encrypted z (payload): {encrypted['z'][:50]}...")
# Step 2: Decrypt
print("\n" + "-" * 80)
print("🔓 Step 2: Decrypting...")
print("-" * 80)
timestamp, iv, decrypted_payload = decrypt_bubble_payload(
appname,
encrypted['x'],
encrypted['y'],
encrypted['z']
)
# Parse decrypted JSON
decrypted_json = json.loads(decrypted_payload.decode('utf-8'))
print(f"✅ Decrypted Timestamp: {timestamp}")
print(f"✅ Decrypted IV (hex): {iv.hex()}")
print(f"\n📄 Decrypted Payload:")
print(json.dumps(decrypted_json, indent=2, ensure_ascii=False))
# Step 3: Verify
print("\n" + "-" * 80)
print("✓ Step 3: Verification")
print("-" * 80)
# Check timestamp
if timestamp == encrypted['timestamp']:
print("✅ Timestamp matches!")
else:
print(f"❌ Timestamp mismatch: {timestamp} != {encrypted['timestamp']}")
# Check IV
if iv.hex() == encrypted['iv']:
print("✅ IV matches!")
else:
print(f"❌ IV mismatch: {iv.hex()} != {encrypted['iv']}")
# Check payload
if decrypted_json == test_payload:
print("✅ Payload matches perfectly!")
else:
print("❌ Payload mismatch!")
print(f"Original: {test_payload}")
print(f"Decrypted: {decrypted_json}")
print("\n" + "=" * 80)
print("🎉 Test completed successfully!")
print("=" * 80)
def test_with_known_values():
"""Test with example encrypted values"""
print("\n\n" + "=" * 80)
print("🔬 Example: Testing with Known Values")
print("=" * 80)
print("\nThis test is disabled by default.")
print("To test with real values, add your encrypted data here.")
print("=" * 80)
if __name__ == "__main__":
# Run test 1: Round trip encryption/decryption
test_encryption_decryption()
# Run test 2: Known values
test_with_known_values()