Last active
February 27, 2020 04:14
-
-
Save tianhaoz95/5b21d38630684366407ef5dadaa0afe6 to your computer and use it in GitHub Desktop.
Simplified code for encoding byte messages into images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Steps for encoding the message | |
| Uint16List expandedMsg = expandMsg(msg2bytes(msg)); | |
| Uint16List paddedMsg = padMsg(getEncoderCapacity(img), expandedMsg); | |
| /// Helper function to convert string to bytes | |
| Uint16List msg2bytes(String msg) { | |
| return Uint16List.fromList(msg.codeUnits); | |
| } | |
| /// Helper function to expand byte messages to bit messages | |
| Uint16List expandMsg(Uint16List msg) { | |
| Uint16List expanded = Uint16List(msg.length * dataLength); | |
| for (int i = 0; i < msg.length; ++i) { | |
| int msgByte = msg[i]; | |
| for (int j = 0; j < dataLength; ++j) { | |
| int lastBit = msgByte & 1; | |
| expanded[i * dataLength + (dataLength - j - 1)] = lastBit; | |
| msgByte = msgByte >> 1; | |
| } | |
| } | |
| return expanded; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment