Skip to content

Instantly share code, notes, and snippets.

View tianhaoz95's full-sized avatar

Tianhao Zhou tianhaoz95

View GitHub Profile
@tianhaoz95
tianhaoz95 / example.java
Created January 30, 2020 23:01
instabug example
import io.flutter.app.FlutterApplication;
import com.instabug.instabugflutter.InstabugFlutterPlugin;
import java.util.ArrayList;
public class CustomFlutterApplication extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
ArrayList<String> invocationEvents = new ArrayList<>();
invocationEvents.add(InstabugFlutterPlugin.INVOCATION_EVENT_SHAKE);
@tianhaoz95
tianhaoz95 / android_device_matrix.yml
Created February 17, 2020 05:57
Define a device matrix to be tested
strategy:
matrix:
device:
- "pixel"
- "pixel_xl"
- "pixel_c"
- "Nexus 6"
fail-fast: false
@tianhaoz95
tianhaoz95 / spin_up_emulator.yml
Created February 17, 2020 06:07
Spin up android emulator for integration tests
- name: run tests
timeout-minutes: 30
uses: reactivecircus/android-emulator-runner@v2
env:
ANDROID_SIGN_PWD: ${{ secrets.ANDROID_SIGN_PWD }}
SECRET_REPO: ${{ secrets.SECRET_REPO }}
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
with:
api-level: 29
profile: ${{ matrix.device }}
@tianhaoz95
tianhaoz95 / setup_environment.yml
Last active February 17, 2020 06:18
set up environment for android device testing
jobs:
android-integration-test:
name: run integration test on Android emulator
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '8.x'
- uses: subosito/flutter-action@v1
@tianhaoz95
tianhaoz95 / encode_message.dart
Last active February 27, 2020 04:14
Simplified code for encoding byte messages into images
/// 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
@tianhaoz95
tianhaoz95 / encode_pixels.dart
Created February 27, 2020 04:13
Simplified version of encoding messages into pixels
/// Steps to encode the entire byte messages into images
for (int i = 0; i < getEncoderCapacity(img); ++i) {
encodedImg[i] = encodeOnePixel(img[i], paddedMsg[i]);
}
/// Helper function to encode one bit of message into 8 pixels
int encodeOnePixel(int pixel, int msg) {
int lastBitMask = 254;
int encoded = (pixel & lastBitMask) | msg;
return encoded;
@tianhaoz95
tianhaoz95 / encrypt_message.dart
Created February 27, 2020 04:15
Lines to encrypt messages
crypto.Key key = crypto.Key.fromUtf8(padCryptionKey(token));
crypto.IV iv = crypto.IV.fromLength(16);
crypto.Encrypter encrypter = crypto.Encrypter(crypto.AES(key));
crypto.Encrypted encrypted = encrypter.encrypt(msg, iv: iv);
msg = encrypted.base64;
@tianhaoz95
tianhaoz95 / extract_bits.dart
Created February 27, 2020 04:35
Extract bits from pixels
Uint16List extractBitsFromImg(Uint16List img) {
Uint16List extracted = Uint16List(img.length);
for (int i = 0; i < img.length; i++) {
extracted[i] = extractLastBit(img[i]);
}
return extracted;
}
@tianhaoz95
tianhaoz95 / bits_to_bytes.dart
Created February 27, 2020 04:38
Convert a list of bits to a list of bytes
Uint16List bits2bytes(Uint16List bits) {
int byteCnt = bits.length ~/ 8;
Uint16List byteMsg = Uint16List(byteCnt);
for (int i = 0; i < byteCnt; ++i) {
Uint16List bitsOfByte = Uint16List.fromList(bits.getRange(i * 8, i * 8 + 8).toList());
int byte = assembleBits(bitsOfByte);
byteMsg[i] = byte;
}
return byteMsg;
}
@tianhaoz95
tianhaoz95 / decrypt_message.dart
Created February 27, 2020 04:40
Decrypt message from the encrypted message string
crypto.Key key = crypto.Key.fromUtf8(padCryptionKey(token));
crypto.IV iv = crypto.IV.fromLength(16);
crypto.Encrypter encrypter = crypto.Encrypter(crypto.AES(key));
crypto.Encrypted encryptedMsg = crypto.Encrypted.fromBase64(msg);
msg = encrypter.decrypt(encryptedMsg, iv: iv);