The XOR Encryption algorithm is a effective and easy to implement method of symmetric encryption.

Overview

Symmetric XOR cipher library

platform_info Actions Status Coverage License: MIT Linter

About XOR cipher

XOR Encryption is an encryption method used to encrypt data and is hard to crack by brute-force method, i.e generating random encryption keys to match with the correct one. The XOR Encryption algorithm is a very effective yet easy to implement method of symmetric encryption. Due to its effectiveness and simplicity, the XOR Encryption is an extremely common component used in more complex encryption algorithms used nowadays. In cryptography, the simple XOR cipher is a type of additive cipher, an encryption algorithm that operates according to the principles:

A XOR 0 = A,
A XOR A = 0,
A XOR B = B XOR A,
(A XOR B) XOR C = A XOR (B XOR C),
(B XOR A) XOR A = B XOR 0 = B

where XOR denotes the exclusive disjunction (XOR) operation. This operation is sometimes called modulus 2 addition (or subtraction, which is identical). With this logic, a string of text can be encrypted by applying the bitwise XOR operator to every character using a given key. To decrypt the output, merely reapplying the XOR function with the key will remove the cipher.

The XOR operator is extremely common as a component in more complex ciphers. By itself, using a constant repeating key, a simple XOR cipher can trivially be broken using frequency analysis. If the content of any message can be guessed or otherwise known then the key can be revealed. Its primary merit is that it is simple to implement, and that the XOR operation is computationally inexpensive. A simple repeating XOR (i.e. using the same key for xor operation on the whole data) cipher is therefore sometimes used for hiding information in cases where no particular security is required. The XOR cipher is often used in computer malware to make reverse engineering more difficult.

If the key is random and is at least as long as the message, the XOR cipher is much more secure than when there is key repetition within a message. When the keystream is generated by a pseudo-random number generator, the result is a stream cipher. With a key that is truly random, the result is a one-time pad, which is unbreakable in theory.

The XOR operator in any of these ciphers is vulnerable to a known-plaintext attack, since plaintext ^ ciphertext = key. It is also trivial to flip arbitrary bits in the decrypted plaintext by manipulating the ciphertext. This is called malleability.

Usage example

import 'package:xor_cipher/xor_cipher.dart';

void main() {
  const source = 'Hello 🦊 world!!!';
  const secret = 'Top 😺 secret';
  print(
    'Source: $source\n'
    'Secret: $secret',
  );
  final encrypted = XOR.encrypt(source, secret, urlEncode: true);
  print('Encrypted: $encrypted');
  final decrypted = XOR.decrypt(encrypted, secret, urlDecode: true);
  print(
    'Decrypted: $decrypted\n'
    'Identical: ${identical(source, decrypted)}',
  );
}

Coverage

Changelog

Refer to the Changelog to get all release notes.

Maintainers

Plague Fox

License

MIT

You might also like...

This is a repository for Flutter Focused Menu, an easy to implement package for adding Focused Long Press Menu to Flutter Applications

This is a repository for Flutter Focused Menu, an easy to implement package for adding Focused Long Press Menu to Flutter Applications

Focused Menu This is an easy to implement package for adding Focused Long Press Menu to Flutter Applications Current Features Add Focused Menu to Any

Dec 26, 2022

An easy to implement custom switch created for Flutter.

An easy to implement custom switch created for Flutter.

flutter_switch An easy to implement custom switch created for Flutter. Give it a custom height and width, border for the switch and toggle, border rad

Dec 6, 2022

A Very Flexible Widget that can Implement Material Sheets on all Directions, both modal and persistent, and consequently a Material Navigation Drawer

Flutter_MaterialSheetAndNavigationDrawer If this project helped you reduce developement time or you just want to help me continue making useful tools

Dec 4, 2021

A quick sample app on how to implement a friend list and a profile page in Flutter.

A quick sample app on how to implement a friend list and a profile page in Flutter.

FlutterMates All code resides in the /lib folder: there's no Android / iOS specific code needed. The article, slides and how this came to be, is here.

Jan 8, 2023

Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_local_notifications plugin.

Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_local_notifications plugin.

Flutter Local Notifications Example Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_l

Nov 29, 2022

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Simplify Equality Comparisons Overview Being able to compare objects in Dart often involves having to override the == operator as well as hashCode. No

Jan 8, 2023

Flutter plugin to implement a Boom Menu, with icons, title, subtitle, animated FAB Icons and hide on scrolling.

Flutter plugin to implement a Boom Menu, with icons, title, subtitle, animated FAB Icons and hide on scrolling.

Flutter Boom Menu Usage The BoomMenu widget is built to be placed in the Scaffold.floatingActionButton argument, replacing the FloatingActionButton wi

Aug 1, 2022

A Package to implement, change and use Themes in Flutter

Modern Themes Github: https://github.com/Jules-Media/Modern_Themes Pub.dev: https://pub.dev/packages/modern_themes About With this Plugin you can impl

Jun 22, 2022

Plugin to implement APNS push notifications on iOS and Firebase on Android.

apns Plugin to implement APNS push notifications on iOS and Firebase on Android. Why this plugin was made? Currently, the only available push notifica

May 14, 2022
Releases(1.0.0+1)
Owner
Plague Fox
Talks about @dart-lang and @flutter
Plague Fox
腾讯云 1 Feb 10, 2022
🎨 An opinionated, effective and correct way to provide multiple themes to your app.

theming This is an opinionated and effective way to provide multi-theme choice for your app. theming depends on provider and shared_preference for sta

Chinyeaka Chinonso 3 Nov 28, 2022
A super effective dart library delivering performance & ensuring greater build speed.

A super effective Dart and Flutter library for delivering performante app ?? & ensuring greater build speed ?? . The package has some cook utilizes wh

Rexford Asamoah 2 Nov 22, 2021
Linter rules corresponding to the guidelines in Effective Dart

effective_dart This package is deprecated. Before it was deprecated, it was the way to provide analysis options corresponding to the guidelines in Eff

Honza Bittner 127 Dec 9, 2022
A lightweight & effective Todo app made with Flutter

Blue Diary A lightweight & effective Todo app made with Flutter. Supports English and Korean. Screenshots • Download • Usage • Architecture • Feedback

Hansol Lee 152 Dec 6, 2022
Tic Tac Toe game with single-player and multi-player options. Implemented minimax algorithm.

flutter_tic_tac_toe A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

null 0 Jan 1, 2022
Open-source, cross-platform, hassle-free file sharing with AES-256 encryption made with Flutter & Dart.

Odin ⚡ Open source easy file sharing for everyone. ⚡ Cross-platform hassle-free file sharing with AES-256 encryption made with Flutter & Dart. Getting

Odin 111 Dec 22, 2022
Mildly encrypted package - An encryption client & server for Dart Native + mobile platforms.

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

Andrew Stein 0 Jan 9, 2022
Cross-Platform Google Drive client with encryption support.

arthurmorgan A Cross-Platform Google Drive client with encryption support. Features implemented Google OAuth2 Upload Files Download Single Files Uploa

Washiul Alam Sohan 45 Aug 14, 2023
Split Korean text into sentences using heuristic algorithm

Korean Sentence Splitter Split Korean text into sentences using heuristic algorithm. pub.dev

자유해결사 3 Nov 28, 2022