cypherEncrypt function

String cypherEncrypt(
  1. String input, {
  2. String sequence = defaultSequence,
  3. int steps = 1,
})

Encrypts a plain string using substitution cipher with step control. Works directly on UTF-8, no Base64 involved.

Implementation

String cypherEncrypt(
    String input, {
      String sequence = defaultSequence,
      int steps = 1,
    }) {
  final encrypted = input.split('').map((char) {
    final idx = sequence.indexOf(char);
    if (idx == -1) {
      // char not in sequence -> leave unchanged
      return char;
    }
    return sequence[(idx + steps) % sequence.length];
  }).join();

  return encrypted;
}