hey folks , i was working on a proxy , dont want to leech and hook , need to get it all done by me
done basic client-server connection and added RSA encryption/decryption but there is some bugs
1- only accept numbers from client to server
2- BUG when trying to encrypt the numbers and decrypt them
idea
its client send string to enc. section and it take it back as double , it send it as byte array , server decrypt it and show the decryption as string (the bug is if inpute was 123456 the output will be nan
not 123456)
EDIT : this was for an infinite number inside calculations , fixed in client but not able to do the same with server , working on it also on new base , will be updated tomorrow
need help to fix/develop it (its all done in couple of days learning c#)
got couple more questions
here the code source
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using NextProxytest0._2;
namespace NextProxytest0._4
{
class Program
{
static void Main(string[] args)
{
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
listener.Bind(new IPEndPoint(IPAddress.Any, 5555));
listener.Listen(100);
Socket connection = listener.Accept();
Console.WriteLine("port 5555 is on and accepting all connections from any client" + "\n");
Console.WriteLine("waiting connection" + "\n");
if (connection.Connected)
Console.WriteLine("client connected" + "\n");
byte[] buffer = new byte[1024]; // this will be our client buffer
NextProxytest0._2.encryption.encryption dobject;
dobject = new NextProxytest0._2.encryption.encryption();
while (connection.Connected)
{
Console.WriteLine("now we are connected and waiting for packets (buffer to be sent)" + "\n");
byte[] rec = null;
int lenght = connection.Receive(buffer, SocketFlags.None);
if (lenght > 0 && lenght < 1025)
rec = new byte[lenght];
Array.Copy(buffer, rec, lenght);
Console.WriteLine("recived packets encrypted (encoding.ascii.getstring(rec) : " + "\n");
Console.WriteLine("\n" + Encoding.ASCII.GetString(rec) + "\n");
Console.WriteLine("recived packets decrypted dobject.decrypte( Encoding.ASCII.GetString(rec) : " + "\n");
Console.WriteLine("\n" + dobject.decrypte( Encoding.ASCII.GetString(rec) ) + "\n");
}
if (connection.Connected == false)
Console.WriteLine("connection disconnected" + "\n");
if (listener.Connected == false)
Console.WriteLine("listener.connected is false" + "\n");
Console.ReadLine();
}
}
}
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using NextProxytest0._2.encryption;
namespace NextProxytest0._2.Client_Server
{
class Client
{
public static void m()
{
Socket connection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
connection.Connect("127.0.0.1", 5555);
encryption.encryption eobject;
eobject = new encryption.encryption();
while (connection.Connected)
{
Console.WriteLine("client connected to server on ip : 127.0.0.1 and port 5555" + "\n");
Console.WriteLine("client is ready to send packets , please enter some string to be sent as byte array ONLY NUMBERS AVILABLE CHARCTERS IS NOT" + "\n");
eobject = new encryption.encryption();
string buffertobesent = Console.ReadLine();
connection.Send(Encoding.ASCII.GetBytes(eobject.encrypte(buffertobesent)));
Console.WriteLine("\n" + "client send to the server this following packets : " + buffertobesent + "\n");
}
Console.WriteLine("disconnected" + "\n");
Console.ReadLine();
}
}
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NextProxytest0._2.Client_Server;
using System.IO;
namespace NextProxytest0._2.encryption
{
//basic RSA encryption
public class encryption
{
public string BytesToEncryptec;
// this is the encryption section where ill start doing basic encryption on it
public string encrypte(string BytesToEncrypte)
{
// to encrypte u should use C = M^E mod N
// to decrypte u should use M = C^D mod N
//where E,N is public key : such that 1<E<piN(@N)
// where N,D is private key
// where M is the packets
// we gona cut it down to parts if M<N
// equation used N = P*q
// @N(piN) = (P-1) * (q-1)
// DE = 1 + K(piN)
double bte = Convert.ToDouble(BytesToEncrypte);
NextProxytest0._2.encryption.option optionobject;
optionobject = new NextProxytest0._2.encryption.option();
bte = Math.Pow(bte,optionobject.E) % optionobject.N ;
string btes = Convert.ToString(bte);
return(btes);
}
public string decrypte(string BytesToDecrypte)
{
//M = C^D mod N
double btd = Convert.ToDouble(BytesToDecrypte);
NextProxytest0._2.encryption.option optionobject;
optionobject = new NextProxytest0._2.encryption.option();
double M = Math.Pow(btd, optionobject.D) % optionobject.N;
string ms = Convert.ToString(M);
return (ms);
}
}
}
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NextProxytest0._2.encryption
{
public partial class option : Form
{
public int p;
public int q;
public long E; //public encryption
public long N; //public modulus
public int piN; //pi the public modulus
public float D; //private exponent
public int k = 5;
public option()
{
InitializeComponent();
}
public string calcprocess(string cb)
{
p = 61; // sure u may change p,q,e,k
q = 53;
N = p * q;
piN = (p - 1) * (q - 1);
E = 17;
D = 1 + (piN * k) / E;
return (cb);
}
}
}
also i got couple of questions over here
- what i read about cryptography was only the RSA , so what the dh,blowfish,encryptionkey is ?
- any useful tut or book about handling data/packets ?
- any useful info about creating proxy ?
thanks for helping , sorry if it was long also if u find the codesource not useful for u
codesource in attachments
ill adding disconnection , seal , proxy(middleman) once i fix bugs in this , its my 0.06 beta :P been 3 days learning(C#) so dont go hard on me but ma asm is fine
special thanks for pro4never for his tuts :P
another download link for the attachments : [
[Only registered and activated users can see links. Click Here To Register...]]
scan for the attachments :
[Only registered and activated users can see links. Click Here To Register...]
humans die but ideas never