Bookmark this: tool.io/convert/caesar-cipher/source-code
Caesar Cipher Source Code
Browse the implementation files for Caesar Cipher.tool.ts typescript
import { parseInteger } from '../../parse/integer/tool';
import { rotateLatinText as rotatePortableLatinText } from '@tool.io/tools/convert/caesar-cipher';
export const rotateLatinText = (
input: string,
rotation: number
): string => rotatePortableLatinText(input, rotation) ?? '';
export const caesarCipher = (
input: unknown,
rotationInput: unknown
): string => {
if (typeof input !== 'string' || input === '') return '';
const rotation = parseInteger(rotationInput);
return rotation === null
? ''
: rotateLatinText(input, rotation);
};
export const Tool: TypeTool = {
name: 'Caesar Cipher',
slug: 'convert/caesar-cipher',
intro:
'Rotate English letters by a custom number of alphabet positions while preserving case, spacing, punctuation, and non-Latin text.',
tool: caesarCipher,
i: [
{
example: 'Tool.io',
label: 'Text',
placeholder: 'Enter text to rotate...',
render: 'textarea',
type: 'text'
},
{
example: '3',
label: 'Rotation',
placeholder: 'Alphabet positions',
type: 'number'
}
],
o: [
{
example: 'Wrro.lr',
label: 'Rotated Text',
placeholder: 'Rotated text will appear here...',
render: 'textarea',
type: 'text'
}
],
alternative: [
{ title: 'ROT13 Converter', url: '/convert/rot13' },
{ title: 'Encode Base64', url: '/encode/base64' }
],
cite: [
{
title: 'Caesar cipher - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Caesar_cipher'
}
]
};
export default Tool;
Description
Browse the implementation files for Caesar Cipher.