cypherDecrypt function

String cypherDecrypt(
  1. String encoded, {
  2. String sequence = defaultSequence,
  3. int steps = 1,
})

Decrypts a string encrypted with cypherEncrypt.

Implementation

String cypherDecrypt(
    String encoded, {
      String sequence = defaultSequence,
      int steps = 1,
    }) {
  final decrypted = encoded.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) % sequence.length];
  }).join();

  return decrypted;
}