textEncryption static method

String textEncryption(
  1. String plainText
)

Encryption plainText and generate random key

Implementation

static String textEncryption(String plainText) {
  // Setup letter to encryption and decryption
  LettersInit.instance.setupLetters();

  // generate Key
  KeyModel keyModel = GenerateKey.generateNewKey();

  // Convert Plain String to list of plain int
  List<int> plainToIntList = _convertPlainToInt(plainText);

  // Encrypt list<int>
  int i = 0;
  List<int> encryptedInts = [];
  while (i < (keyModel.key) + (keyModel.key % 263)) {
    encryptedInts = _encryptListInt(
      i == 0 ? plainToIntList : encryptedInts,
      keyModel.key,
    );
    ++i;
  }

  //  Convert list<int> to cipher text
  String encryptedString =
      _convertEncryptedIntToEncryptedString(encryptedInts);

  // Hide key in cipher text to extract it when decrypt
  String encryptedStringWithKey = _addKeyToCipheredText(
    encryptedString,
    keyModel.letters,
  );

  String encryptedStringWithKeyWithLength =
      _addLengthToCipheredText(encryptedStringWithKey);

  return encryptedStringWithKeyWithLength;
}