## Posts

### RSA encryption in JAVA with custom key length

This code is written in three section which you can divide and use each one separately.
1. Generating custom RSA keys.
2. Use Java "security" and "crypto" API to encrypt and decrypt the text.
2. Use keys produced by API and use my algorithm to encrypt and decrypt.

-This program is written by Shooresh Sufiye. Feel free to copy and change it, But don't forget to mention the source.

// Written by Shooresh Sufiye 2017 Oct Halmstad

import java.io.File;
import java.io.FileInputStream;
import java.util.*;
import java.math.BigInteger;
import java.io.*;

import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import javax.crypto.*;

//import com.sun.java_cup.internal.runtime.Scanner;
//import com.sun.java_cup.internal.runtime.Symbol;

public class q467 {
private final static BigInteger one = new BigInteger("1");
private final static SecureRandom random = new SecureRandom();

private BigInteger privat…

### Diffie-Hellman key generation in Python

In this code, I used math class only. here I implement Deffie-Hellman algorithm for produce public and private keys for Alice and Bob.
This program was written by Shooresh Sufiye. you can copy and change it, But don't forget to mention the source.

# Written by Shooresh Sufiye
import random
from math import *

class DH:
sharedSec=None

def __init__(self):
self.cal()

def gimmi(self, v):
p = int(random.random() *1000000)
p1 = p+100
if(p>p1): p,p1=p1,p
primesList=[]
primesList = [i for i in range(p,p1) if ((len(primesList)<=5) and self.isPrime(i))]
p=random.choice(primesList)
primesList.remove(p)
P = p
return P

def isPrime(self, a):
isp = None
b=int(sqrt(a))
# should change to stave alg or better
while(b>1):
if(a%b==0):
isp = False
b=-1
break
…

### RSA Public and Private key generation in Python

In this code, the only third-party library is "secrets" which is available to download and add automatically to python libraries by executing pip command.

-This program was written by Shooresh Sufiye. Feel free to copy and change it, But don't forget to mention the source.

# Written by Shooresh Sufiye
# RSA Algorithm Shooresh
from math import *
import random
import secrets

#===============-RSA key Class-==================
class RSAkey:
publicKey = []
PrivateKey = []
sp = 0
sq = 0
dig = 0
def __init__(self,sp,sq,length):
self.sp = int(sp)
self.sq = int(sq)
self.dig = int(length)
self.cal()

def getKeys(self):
keyl = []
keyl.append(self.publicKey)
keyl.append(self.PrivateKey)
return keyl
#+++++++++++++++++++-bigPrime Class-+++++++++++++++++++++++
class bigPrime:
P=None

def  __init__(self):
self.P=None

def isPrime(self, a)…

### One-Time Pad Encryption - In Python

In this code, no library used and everything done by standard functions of python. Simple and easy to understand.
This code reads plain text and key from text files.
This program was written by Shooresh Sufiye. you can copy and change it, But don't forget to mention the source.

# Written by:  Shooresh Sufiye
#
f = open("plain.txt", "r")
f.close()
print ("plain text:\n ", allplain)

f = open("plain.txt", "rb+")
kf = open ("key.txt", "rb" )
f2= open("cipher.txt", "r+")

key =[]
#   - encrypt plain text and save into cipher.txt

for i in range(len(allplain)):
k = chr (key[i])
p = chr (allplain[i])
c = chr ((ord(p)) ^ (ord(k)))
f2.write(c)

f.close()
f2.close()
kf.close()

f2 = open("plain2.txt", "r+")
kf = open ("key.txt", "rb" )
f= open("cipher.txt", "rb+") 