11package org.vonderheidt.hips.utils
22
3- import kotlinx.coroutines.delay
3+ import org.vonderheidt.hips.data.Settings
44
55/* *
66 * Object (i.e. singleton class) that represents steganography encoding and decoding.
@@ -9,22 +9,56 @@ object Steganography {
99 /* *
1010 * Function to encode secret message into cover text using given context.
1111 */
12- suspend fun encode (context : String , secretMessage : String ): String {
13- // Wait 5 seconds
14- delay(5000 )
12+ suspend fun encode (
13+ context : String ,
14+ secretMessage : String ,
15+ conversionMode : ConversionMode = Settings .conversionMode,
16+ steganographyMode : SteganographyMode = Settings .steganographyMode
17+ ): String {
18+ // Step 1: Convert secret message to a (compressed) binary representation
19+ val plainBits = when (conversionMode) {
20+ ConversionMode .Arithmetic -> { Arithmetic .decode(" " , secretMessage) } // Stegasuras: Arithmetic binary conversion is just decoding with empty context
21+ ConversionMode .UTF8 -> { UTF8 .encode(secretMessage) }
22+ }
1523
16- // Return placeholder string
17- return " Encode of $secretMessage using $context "
24+ // Step 2: Encrypt binary representation of secret message
25+ val cipherBits = Crypto .encrypt(plainBits)
26+
27+ // Step 3: Encode encrypted binary representation of secret message into cover text
28+ val coverText = when (steganographyMode) {
29+ SteganographyMode .Arithmetic -> { Arithmetic .encode(context, cipherBits) }
30+ SteganographyMode .Bins -> { Bins .encode(context, cipherBits) }
31+ SteganographyMode .Huffman -> { Huffman .encode(context, cipherBits) }
32+ }
33+
34+ return coverText
1835 }
1936
2037 /* *
2138 * Function to decode secret message from cover text using given context.
22- */
23- suspend fun decode (context : String , coverText : String ): String {
24- // Wait 5 seconds
25- delay(5000 )
39+ */
40+ suspend fun decode (
41+ context : String ,
42+ coverText : String ,
43+ conversionMode : ConversionMode = Settings .conversionMode,
44+ steganographyMode : SteganographyMode = Settings .steganographyMode
45+ ): String {
46+ // Invert step 3
47+ val cipherBits = when (steganographyMode) {
48+ SteganographyMode .Arithmetic -> { Arithmetic .decode(context, coverText) }
49+ SteganographyMode .Bins -> { Bins .decode(context, coverText) }
50+ SteganographyMode .Huffman -> { Huffman .decode(context, coverText) }
51+ }
52+
53+ // Invert step 2
54+ val plainBits = Crypto .decrypt(cipherBits)
55+
56+ // Invert step 1
57+ val secretMessage = when (conversionMode) {
58+ ConversionMode .Arithmetic -> { Arithmetic .encode(" " , plainBits) } // Stegasuras: Arithmetic string conversion is just encoding with empty context
59+ ConversionMode .UTF8 -> { UTF8 .decode(plainBits) }
60+ }
2661
27- // Return placeholder string
28- return " Decode of $coverText using $context "
62+ return secretMessage
2963 }
3064}
0 commit comments