Author Topic: Programming V3 MEGATHREAD [Because we need one]  (Read 6612 times)

the rsa system?
The Miller-Rabin primality test.

And on my note that your variable type has to be able to hold modulus * modulus without overflow to do modular exponentiation right, there are libraries out there that let you store numbers of any size without any overflow that you can use.

The Miller-Rabin primality test.

And on my note that your variable type has to be able to hold modulus * modulus without overflow to do modular exponentiation right, there are libraries out there that let you store numbers of any size without any overflow that you can use.

what are the chances of these other primality tests failing?

also idk why i like to do everything standard. i usually stay away from non standard libraries like boost or whatever unless i have no other choice because for some reason it feels like youre being spoon fed

The chances of trial division failing (assuming you try all the way up to sqrt(n)) is 0%. You've checked it against every single possible prime number there is!

But the point is that you can get immensely faster speeds by doing a probabilistic test.

For example, most professionally made programs that incorporate RSA use the miller-rabin test with 64 iterations. This means that there is a 0.000000000000000000000000000 0000000003% chance that the number they chose isn't a prime, and the time to check that is on the order of 108x faster than trial division.

And you kind of have to use the bignum libraries in order to get in the range of actual secure numbers for RSA. The most well-known one out there is the GNU MP library.

oh i see. thats good to know, ill probably switch over to the miller primality test

And you kind of have to use the bignum libraries in order to get in the range of actual secure numbers for RSA. The most well-known one out there is the GNU MP library.

ill check it out thanks
« Last Edit: February 21, 2014, 03:25:59 PM by Blockzillahead »

Damn no wonder that code was slow, cout is being called in the loop

Code: [Select]
#include <iostream>
#include <cmath>
#include <ctime>
#include <fstream>
#include <vector>

bool isPrimeSuperOptimized(long long number)
{
if (number < 2) return false;
if (number == 2) return true;
if (number == 3) return true;
if (number == 5) return true;
if (!(number % 2)) return false;
if (!(number % 3)) return false;
if (!(number % 5)) return false;
if (number < 7*7) return true;
int step[] = {7,11,13,17,19,23,29,31};
int sentry = (int)sqrt((double)number);
for(int r = 0; r < sentry; r += 30)
            for(int i = 0; i < 8; ++i)
                if (!(number % (r+step[i])))
                    return false;
return true;
}

int main()
{
    std::cout.sync_with_stdio(false);
    std::vector<long long> primes;
    long long number = 10000000;
    std::clock_t startfunction3;
    double function3;
    startfunction3 = std::clock();
    for(int i = 2; i < number; i++)
    {
        if(isPrimeSuperOptimized(i))
        {
            std::cout << i << " ";
            primes.push_back(i);
        }
    }
    function3 = ( std::clock() - startfunction3 ) / (double)CLOCKS_PER_SEC;
    std::cout << "\nFinished: " << function3;
    std::cout << "\nAdding to list: ";
    long long primesize = primes.size();
    std::ofstream file;
    file.open("primes.txt");
    for(int i = 0; i < primesize; i++)
    {
        file << primes[i] << std::endl;
    }
    return 0;
}
Running primes up to 10,000,000 and then adding them to vector then a file after.
Thing is if I run this without the line "std::cout.sync_with_stdio(false);" I get somewhere around 95 run time.
If I run with that line, I get 6 run time
lol obviously this wouldnt be a real problem in an actual system because youre not printing them to the screen so youre saving energy without calling cout, but eesh thats a huge difference and really bad one too

aw just found out my rsa system doesnt actually work. its fake and its really weird.

step #1
you encrypt a string
you get the numbers
//Enter decryption system
then decrypt it with the numbers
you get the correct string

step #2
restart whole main again
you encrypt a different string
you get numbers
//Enter decryption system
you use numbers from the first step 1
you get a decrypted string, which is the exact same one from step 2. this makes no sense because of how its called.

really disappointing. how did it slip by me so bad

I learned some code from this guy on youtube.
Last thing I learned was variables.
Where should I continue?
I've learned alert("");, document.write("");, variables, like i just said, and sadly that's it.

JavaScript functions, probably.

Question: Why are you using RSA for a secure message channel anyway?
why not use curve25519 or something to establish a symmetric key.
It's faster/more secure.

Question: Why are you using RSA for a secure message channel anyway?
why not use curve25519 or something to establish a symmetric key.
It's faster/more secure.

its not a choice of one or the other. the smart move is to use both asymmetric and symmetric encryption. like RSA and AES
besides im learning a lot from this.

also symmetric is not more secure than asymmetric.
anyone can intercept a single key and use it to decrypt your symmetric encryption.
with asymmetric thats impossible because the only key youre giving out, is the one thats used to only encrypt the string, it cannot decrypt while a symmetric key can do both.

good news is i fixed the rsa
now its going character by character instead of all together
« Last Edit: February 22, 2014, 12:27:13 PM by Blockzillahead »

Question: are you using RSA to actually encrypt things or just exchange a key

because if you're doing the former then you should be stopping

i was thinking i should first encrypt symmetrically the message then asymmetrically encrypt both the symmetric message and key but now i think it would be easier to symmetrically encrypt the message and just asymmetrically encrypt the key

Nooonononono, that's not how secure key exchange works.

Take a look at this: http://youtu.be/3QnD2c4Xovk

Nooonononono, that's not how secure key exchange works.

Take a look at this: http://youtu.be/3QnD2c4Xovk
so i should just use rsa to encrypt the message and send it?

you send someone a public key, the encrypt their stuff, then they send you the stuff and you decrypt it with the private key. that should be good enough for sending messages across

Quote from: Blockzillahead link=topic=252068.msg7311538#msg7311538 date=1393090168
[/quote
this is why you don't implement your own crypto
You have heard that before, haven't you?