diff --git a/src/pages/string/index.ts b/src/pages/string/index.ts index f7eed37..43714ca 100644 --- a/src/pages/string/index.ts +++ b/src/pages/string/index.ts @@ -1,3 +1,4 @@ +import { tool as stringRot13 } from './rot13/meta'; import { tool as stringReverse } from './reverse/meta'; import { tool as stringRandomizeCase } from './randomize-case/meta'; import { tool as stringUppercase } from './uppercase/meta'; diff --git a/src/pages/string/rot13/index.tsx b/src/pages/string/rot13/index.tsx new file mode 100644 index 0000000..2814f13 --- /dev/null +++ b/src/pages/string/rot13/index.tsx @@ -0,0 +1,11 @@ +import { Box } from '@mui/material'; +import React from 'react'; +import * as Yup from 'yup'; + +const initialValues = {}; +const validationSchema = Yup.object({ + // splitSeparator: Yup.string().required('The separator is required') +}); +export default function Rot13() { + return Lorem ipsum; +} \ No newline at end of file diff --git a/src/pages/string/rot13/meta.ts b/src/pages/string/rot13/meta.ts new file mode 100644 index 0000000..86ee585 --- /dev/null +++ b/src/pages/string/rot13/meta.ts @@ -0,0 +1,13 @@ +import { defineTool } from '@tools/defineTool'; +import { lazy } from 'react'; +// import image from '@assets/text.png'; + +export const tool = defineTool('string', { + name: 'Rot13', + path: 'rot13', + // image, + description: '', + shortDescription: '', + keywords: ['rot13'], + component: lazy(() => import('./index')) +}); \ No newline at end of file diff --git a/src/pages/string/rot13/rot13.service.test.ts b/src/pages/string/rot13/rot13.service.test.ts new file mode 100644 index 0000000..ce7fac5 --- /dev/null +++ b/src/pages/string/rot13/rot13.service.test.ts @@ -0,0 +1,58 @@ +import { expect, describe, it } from 'vitest'; +import { rot13 } from './service'; + +describe('rot13', () => { + it('should encode a simple string using ROT13', () => { + const input = 'hello'; + const result = rot13(input); + expect(result).toBe('uryyb'); + }); + + it('should decode a ROT13 encoded string', () => { + const input = 'uryyb'; + const result = rot13(input); + expect(result).toBe('hello'); + }); + + it('should handle uppercase letters correctly', () => { + const input = 'HELLO'; + const result = rot13(input); + expect(result).toBe('URYYB'); + }); + + it('should handle mixed case letters correctly', () => { + const input = 'HelloWorld'; + const result = rot13(input); + expect(result).toBe('UryybJbeyq'); + }); + + it('should handle non-alphabetic characters correctly', () => { + const input = 'Hello, World!'; + const result = rot13(input); + expect(result).toBe('Uryyb, Jbeyq!'); + }); + + it('should handle an empty string', () => { + const input = ''; + const result = rot13(input); + expect(result).toBe(''); + }); + + it('should handle a string with numbers correctly', () => { + const input = '1234'; + const result = rot13(input); + expect(result).toBe('1234'); + }); + + it('should handle a string with symbols correctly', () => { + const input = '!@#$%^&*()_+-='; + const result = rot13(input); + expect(result).toBe('!@#$%^&*()_+-='); + }); + + it('should handle a string with mixed characters correctly', () => { + const input = 'Hello, World! 123'; + const result = rot13(input); + expect(result).toBe('Uryyb, Jbeyq! 123'); + }); +}); diff --git a/src/pages/string/rot13/service.ts b/src/pages/string/rot13/service.ts new file mode 100644 index 0000000..5030598 --- /dev/null +++ b/src/pages/string/rot13/service.ts @@ -0,0 +1,7 @@ +export function rot13(input: string): string { + return input.replace(/[a-zA-Z]/g, (char) => { + const charCode = char.charCodeAt(0); + const baseCode = charCode >= 97 ? 97 : 65; // 'a' or 'A' + return String.fromCharCode(((charCode - baseCode + 13) % 26) + baseCode); + }); +}