caesarShift static method

String caesarShift(
  1. String text,
  2. int shift
)

Implementation

static String caesarShift(String text, int shift) {
  final int n = ((shift % 26) + 26) % 26;
  return String.fromCharCodes(
    text.runes.map((int c) {
      if (c >= 65 && c <= 90) return (c - 65 + n) % 26 + 65;
      if (c >= 97 && c <= 122) return (c - 97 + n) % 26 + 97;
      return c;
    }),
  );
}