This app is about Cryptography using AES(Advanced Encryption Standard) algorithm, build in Microsoft Visual Studio 2022.
The Key, IV(Initialization Vector) and Ciphertext in Base64 number system.
The key lengths or key size is 128 bit(AES-128), 192 bit(AES-192) and 256 bit(AES-256).
Using lib : --> using System.Security.Cryptography;
using System.Security.Cryptography;
aes.GenerateKey();
aes.GenerateIV();This app to hashing text and file, as the result we got hashing text. Build in Microsoft Visual Studio 2022
-SHA256 is 256 bits(32 bytes) with hexadecimal characters is 64.
-SHA512 is string with 128 hexadecimal character.
-MD5 got 32 hexadecimal char.
Using lib : --> using System.Security.Cryptography;
using System.Security.Cryptography;Implementation of RSA algorithm using Pascal (text base/terminal).
Implementation of RSA algorithm using Lazarus 4.8 FPC 3.2.2.
On the RSA as asymmetric cryptography uses two different keys, e as public key/encrypt key(not secret) & d as private key/decrypt key(secret).
p, q is prime number
k:integer
m:integer
c:integer
The public keys is (n,e)
The private key represent as (n,d) and p, q is secret also.
The idea is to find p first as one of the prime factors, then get q using q=n/p.
The method as follows :
- On this app, the lower boundary required a minimum 3 digits decimal.
- Check n, Eliminate if last digit n is 2 or 5(because there is no composite number as a product of multiply two prime numbers.
- On a 3 digit or higher of prime number, the last digit must be 1 or 3 or 7 or 9 and so with p.
- First find a length digits of n(e.g 11 digits).
- Find digit p using: ceil(digit n/2), e.g, ceil(11/2)=6 digits.
- This method is called the "Slimming Brute Force", where it covers all possibilities to find p.
- After length digits of p or q found, we find all prime numbers(or candidates p) on [a,b], where a= 10^(m-1), b=(10^m)-1, where m is length digit of p. Example m=3, so p on the [100,999] with assume p & q got the same length digit.
- If two factors have different length digit then we use the 2nd scenario where we decrease a as the left boundary to find candidates of p where a becomes a= 10^(m-1-g), g start from 1. Now a=10(2 digit), [a,b] becomes [10,99],and so on.
- We can use the Sieve of Atkin algorithm to find all prime numbers on a given interval.
- We try the first scenario with assume p, q got the same length digit(it's usually used, because if one of the factor got shorter digit, easier to break), and try others scenarios till found p(automatically found q also). We got all candidates for p.
- Check the right candidate use: if (n mod p)=0 then p found & find q using q=n/p.
- We already had e, p, q.
- d=(1+k phi(n))/e ; we loop k as integer till satisfied the equation(start with k=1).
- Finally we got d as our private key.
On folder CryptoRoot. Build on Lazarus 4.8 FPC 3.2.2.
- Using single key 16 digits decimal.
- Polynomial with 4 terms as follows:
$F(x) = c_1(x)^{d1}+c_2(x)^{d2}+ c_3(x)^{d3}+c_4(x)^{d4}$
$where \ c : coefficient ; d : degree$
- Position of digit decimal on key, from 1 to 16, coefficient 1 (digit 1-3), degree 1 (digit 4), coef 2 (digit 5-7), deg 2 (digit 8), coef 3 (digit 9-11), deg 3 (digit 12) and coef 4 (digit ,13-15), deg 4 (digit 16). - Can use 16 digit decimal, e.g key = 4957578310536271.
- So, equation becomes:
$F(x) = 495(x)^{7}+578(x)^{3}+ 105(x)^{3}+627(x)$
- Input ordinal number from character in ASCII to Polynomial F(x), so we got value as constant. Example ordinal(A)=65, so got value of constant on a given ordinal of char.
- Thus
$F(65) = 495(65)^{7}+578(65)^{3}+ 105(65)^{3}+627(65)=2426602993469002$
- Or
$495(x)^{7}+578(x)^{3}+ 105(x)^{3}+627(x)-2426602993469002=0$
- Now we have a Finding-Root problem.
- In this case, I use Newton-Raphson method to solve the problem. Equation as follows:
- As the final result we had the root in the ordinal number after using Newton-Raphson method.
- In the example above the root is 65 (char ‘A’ ).
- The same way, we can apply to the message that is the string of chars and all the constants of each char to be stringing also(on the menu encryption).
- After got the decimal strings of consts as chipertext, we add marker between each const on the form of decimal also. So we knew, every single const when get on menu decryption.
- To make marker, we can define Function F(x), as we liked. In my case use 5 digit every marker to avoid collision with const when use 'copy' as string func.
- To view purposes, decimal string encoded to Base64 on the menu Encryption.
- Next step chipertext Base64 format reverse back to decimal string on menu Decryption, get every consts between marker and find all the roots as ordinal of each characters.
- Finally every single constant convert to characters again & we got the message.
- Notes: try max iteration=50 as average, instead 200. All char that we usually typing from ord 32(space char) till 126(~), so i use p0=50 based on range[32,126], approx midlle position is 50 as single starting point on the Newton-Raphson method. If you like, to makes more scrambled add shift row on the decimal string on encryption and reverse shift row on decryption. Shift row can use math function or just shifting index position.