import 'dart:convert';
import "encrypt_utils.dart";
import 'dart:io';

void main() {
  testMakeVideoFile();
}

void testNormal() {
  var key = "ab11cke22y123";
  var sortTable = getSortTable(key);
  print(sortTable);

  List<int> bytes = utf8.encode(key);
  print(bytes);

  var rndVal = randNum(bytes, 10, 1, 0xff + 1);
  print(rndVal);

  var oriData = utf8.encode("hello");
  var encData = encrypt(oriData, key);
  print(oriData);
  print(encData);

  List<int> decData = decrypt(encData, key);
  print(decData);
  
  var decDataStr = utf8.decode(decData);
  print(decDataStr);

  if(decDataStr != "hello") {
    print("failed.");
  }else{
    print("ok");
  }
}

void testMakeVideoFile() {
  File file = new File('test_data/movie.mp4');
  var data = file.readAsBytesSync();

  var key = "c2AkIbxQLQSToEZQ";
  List<int> encryptData = encrypt(data, key);
  File outfile = new File('test_data/movie_enc.mp4');

  outfile.writeAsBytesSync(encryptData);
}

void testEncImg() {
  var key = "c2AkIbxQLQSToEZQ";

  File file = new File('test_data/1.jpg');
  var data = file.readAsBytesSync();

  Stopwatch stopwatch = new Stopwatch()..start();
  List<int> encryptData = encrypt(data, key);
  print('doSomething() executed in ${stopwatch.elapsed}');
}