caesar_cipher 1.0.0+3 caesar_cipher: ^1.0.0+3 copied to clipboard
This is a package to encrypt and decruptare text, which can be a word, phrase, password etc...
caesar_cipher #
This is a package to encrypt and decruptare text, which can be a word, phrase, password etc... The principle of this package is based on the possibility of replacing letter by letter (of the string in question), with another letter of the alphabet, shifted by "n" letters.
''' import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart';
class CaesarCipher extends StatefulWidget { const CaesarCipher({Key? key}) : super(key: key);
@override State
class _CaesarCipherState extends State
late int shiftUserInput=0; // Number of moves via user input for the Caesar cipher final TextEditingController _inputControllerUserInput = TextEditingController(); final TextEditingController _outputControllerUserInput = TextEditingController();
//-------------------PART OF CODE FOR ENCRYPTING AND DECRYPTING WITH THE NUMBER OF MOVES SET TO USER---------------------- // Function to encrypt text String encryptUserInput(String text, int shift) { String result = ''; for (int i = 0; i < text.length; i++) { String char = text[i]; if (isLetter(char)) { String shiftedChar = String.fromCharCode( (char.codeUnitAt(0) - 'a'.codeUnitAt(0) + shift) % 26 + 'a'.codeUnitAt(0)); result += shiftedChar; } else { result += char; } } return result; }
// Function to decipher text String decryptUserInput(String text, int shift) { return encrypt(text, 26 - shift); }
//-------------------PART OF CODE FOR ENCRYPTING AND DECRYPTING WITH THE NUMBER OF MOVES SET TO 3 MOVES---------------------- // Function to check if a character is a letter bool isLetter(String char) { final pattern = RegExp('[a-zA-Z]'); return pattern.hasMatch(char); }
// Function to encrypt text String encrypt(String text, int shift) { String result = ''; for (int i = 0; i < text.length; i++) { String char = text[i]; if (isLetter(char)) { String shiftedChar = String.fromCharCode( (char.codeUnitAt(0) - 'a'.codeUnitAt(0) + shift) % 26 + 'a'.codeUnitAt(0)); result += shiftedChar; } else { result += char; } } return result; }
// Function to decipher text String decrypt(String text, int shift) { return encrypt(text, 26 - shift); }
@override Widget build(BuildContext context) { return Scaffold( body: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children:
@override void dispose() { _inputController.dispose(); _outputController.dispose(); _inputControllerUserInput.dispose(); _outputControllerUserInput.dispose(); super.dispose(); } } '''