2018-08-31 21:47:18 +02:00
|
|
|
import {Converter} from './converter';
|
|
|
|
|
|
|
|
export class ROT13Converter implements Converter {
|
|
|
|
getDisplayname(): string {
|
|
|
|
return 'Perform ROT-13';
|
|
|
|
}
|
|
|
|
|
|
|
|
getId(): string {
|
2018-09-01 00:44:24 +02:00
|
|
|
return 'rot13';
|
2018-08-31 21:47:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
convert(input: string): string {
|
|
|
|
try {
|
|
|
|
const inChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
|
|
const outChars = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm';
|
|
|
|
const translate = c => {
|
|
|
|
const charIndex = inChars.indexOf(c);
|
|
|
|
return charIndex > -1 ? outChars[charIndex] : c;
|
|
|
|
};
|
|
|
|
return input.split('').map(translate).join('');
|
|
|
|
} catch (exception) {
|
|
|
|
throw new Error('Could not perform ROT-13 conversion. Maybe corrupt input?');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|