Skip to content

Latest commit

 

History

History
82 lines (63 loc) · 2.23 KB

sss.md

File metadata and controls

82 lines (63 loc) · 2.23 KB

ntc_dcrypto

ntc_dcrypto is a module dart cryptography.

1. An implementation of Shamir's Secret Sharing Algorithm 256-bits in Dart

Usage

Use encode/decode Base64Url

import '/ntcdcrypto.dart';

main() {
  SSS sss =  SSS();
  String s = "nghiatcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  print("secret: ${s}");
  print("secret.length: ${s.length}");
  // creates a set of shares
  List<String> arr = sss.create(3, 6, s, true);
  //print(arr);

  // combines shares into secret
  var s1 = sss.combine(arr.sublist(0, 3), true);
  print("combines shares 1 length = ${arr.sublist(0, 3).length}");
  print("secret: ${s1}");
  print("secret.length: ${s1.length}");

  var s2 = sss.combine(arr.sublist(3, arr.length), true);
  print("combines shares 2 length = ${arr.sublist(3, arr.length).length}");
  print("secret: ${s2}");
  print("secret.length: ${s2.length}");

  var s3 = sss.combine(arr.sublist(1, 5), true);
  print("combines shares 3 length = ${arr.sublist(1, 5).length}");
  print("secret: ${s3}");
  print("secret.length: ${s3.length}");
}

Use encode/decode Hex

import '/ntcdcrypto.dart';

main() {
  SSS sss = new SSS();
  String s = "nghiatcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  print("secret: ${s}");
  print("secret.length: ${s.length}");
  // creates a set of shares
  List<String> arr = sss.create(3, 6, s, false);
  //print(arr);

  // combines shares into secret
  var s1 = sss.combine(arr.sublist(0, 3), false);
  print("combines shares 1 length = ${arr.sublist(0, 3).length}");
  print("secret: ${s1}");
  print("secret.length: ${s1.length}");

  var s2 = sss.combine(arr.sublist(3, arr.length), false);
  print("combines shares 2 length = ${arr.sublist(3, arr.length).length}");
  print("secret: ${s2}");
  print("secret.length: ${s2.length}");

  var s3 = sss.combine(arr.sublist(1, 5), false);
  print("combines shares 3 length = ${arr.sublist(1, 5).length}");
  print("secret: ${s3}");
  print("secret.length: ${s3.length}");
}

Run Unittest

cd ntc_dcrypto
flutter test

License

This code is under the Apache License v2.