Skip to content

Commit 02d3fbb

Browse files
Implement UTF-8 conversion
1 parent ce07bcd commit 02d3fbb

File tree

1 file changed

+5
-15
lines changed
  • app/src/main/java/org/vonderheidt/hips/utils

1 file changed

+5
-15
lines changed
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.vonderheidt.hips.utils
22

3-
import kotlinx.coroutines.delay
4-
53
/**
64
* Object (i.e. singleton class) that represents the binary conversion of the secret message using UTF-8 encoding.
75
*
@@ -14,12 +12,8 @@ object UTF8 {
1412
* @param secretMessage Secret message.
1513
* @return Binary representation of the secret message.
1614
*/
17-
suspend fun encode(secretMessage: String): ByteArray {
18-
// Wait 5 seconds
19-
delay(5000)
20-
21-
// Return placeholder
22-
val plainBits = ByteArray(size = 0)
15+
fun encode(secretMessage: String): ByteArray {
16+
val plainBits = secretMessage.toByteArray(charset = Charsets.UTF_8)
2317

2418
return plainBits
2519
}
@@ -30,13 +24,9 @@ object UTF8 {
3024
* @param plainBits Binary representation of the secret message.
3125
* @return Secret message.
3226
*/
33-
suspend fun decode(plainBits: ByteArray): String {
34-
// Wait 5 seconds
35-
delay(5000)
36-
37-
// Return placeholder
38-
val coverText = ""
27+
fun decode(plainBits: ByteArray): String {
28+
val secretMessage = String(bytes = plainBits, charset = Charsets.UTF_8)
3929

40-
return coverText
30+
return secretMessage
4131
}
4232
}

0 commit comments

Comments
 (0)