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

C++ has more abstractions than C, so it can be negligibly slower due to more lines of machine code being compiled. But that reduction in speed only occurs when you're writing C-style code in C++, when you start writing more abstracted code C++ becomes faster than C because these abstractions end up more efficient than what most programmers would write in C. So C is good for stuff like hardware where abstract things like classes are unnecessary and C++ is better for more abstracted things like programs.

How does that effect the security of the language at all? Honest question.

thats what im wondering. the visual microsoft compiler says it not me

Uhhhh. Why not use a string instead? Why would you want to use a char*?

same deal. as in error i mean

It doesn't let you use it as a string anymore because * is supposed to be used as a pointer to a single instance of that type, not an arbitrary number of them.
Well.. not really. Arrays are just consecutive pointers where [#] shifts over by #*sizeofptr to get the pointer to the next instance.

How does that effect the security of the language at all? Honest question.
By security it doesn't mean vulnerability to hacking, it means vulnerability to memory errors. If you don't properly take care of your data in a self-managed language (without a garbage collector) you can easily create a lot of problems very fast, not to mention take up a lot of space that's needed for other programs in RAM.
« Last Edit: February 18, 2014, 03:41:36 PM by $trinick »

why is there no Lua on the charts? is it like <0.01%? lol

why is there no Lua on the charts? is it like <0.01%? lol

that chart is pretty weird though. but lua is pretty low on all the charts

I don't know how they quantify the popularity of languages. By projects hosted on GitHub? By personal survey? I know and use a lot of languages, so the percentages wouldn't add up to 100% if it was a tick all that apply style survey.

I don't know how they quantify the popularity of languages. By projects hosted on GitHub? By personal survey? I know and use a lot of languages, so the percentages wouldn't add up to 100% if it was a tick all that apply style survey.

they probably add it all up from different sites like stackoverflow and stuff. trends of how many topics on a specific language pop up

GitHub sounds like an interesting way to tally a certain languages' usage

heres my best shot at rsa encryption. public code yo
Code: [Select]
//Library
#include <iostream>
//#include <string.h>
//#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <windows.h>

//Prototypes, unneeded
//long long encrypt(long long msg, long long key_n, int key_e);
//long long decrypt(long long encrypted_msg, long long secret_n, long long secret_d);

bool isprime(long long num) //Function to check if number is prime
{
    if(num <= 1)
        return false;
    if(num == 2)
        return true;
    if(num % 2 == 0)
        return false;
    for(int i = 3; i <= sqrt(num * 1.0); i += 2)
    {
        if(num % i == 0)
            return false;
    }
    return true;
}

long long rand_prime(int lower, int upper) //Generate random prime number
{
    long long spread = upper - lower + 1;
    while(1)
    {
        long long p = 1 | (rand() % spread + lower);
        if (isprime(p)) return p;
    }
}

int gcd(long long a, long long b) //Greatest common divisor between two numbers
{
    int temp;
    while(b != 0)
    {
        temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

//Formula: C = P^e % n
long long encrypt(long long msg, long long key_n, int key_e) //Encryption with two keys
{
    long long encrypted_msg = 1; //Set it to a value of 1 for now
    for(int i = 0; i < key_e; i++) //Register for faster performance
    {
        encrypted_msg = encrypted_msg * msg % key_n;
    }
    encrypted_msg = encrypted_msg % key_n;
    return encrypted_msg;
}

//Forumula: P = C^d % n
long long decrypt(long long encrypted_msg, long long secret_n, long long secret_d) //Decryption with two different keys
{
    long long decrypted  = 1;
    for(int i = 0; i < secret_d; i++)
    {
        decrypted = decrypted * encrypted_msg % secret_n;
    }
    decrypted = decrypted % secret_n;
    return decrypted;
}

//Second main
int actualmain()
{
    unsigned long long p; //First prime
    unsigned long long q; //Second prime
    unsigned long long n; //Product of both primes *****THIS IS PART OF BOTH THE PRIVATE AND PUBLIC KEY
    unsigned long long m; //Product of both primes following the (p-1)*(q-1) formula
    unsigned int e; //Coefficient of m *****SECOND PART OF PUBLIC KEY
    unsigned long long d; //d = (1 + nm)/e where n is any number, not the product of both primes *****SECOND PART OF PRIVATE KEY

    p = rand_prime(1000,5000); //Choose two random primes within range
    q = rand_prime(6000,10000);

    //Math formulas below for RSA
    n = p*q;
    m = (p-1)*(q-1);
    e = 0;
    for(int i = 2;; i++)
    {
        if((gcd(i,m)) == 1)
        {
            e = i;
            break;
        }
    }
    for(int a = 0;; a++)
    {
        if((1+(a*m)) % e == 0)
        {
            d = (1+(a*m))/e;
            break;
        }
    }

    //Debugging
    std::cout << "\np = " << p << std::endl;
    std::cout << "q = " << q << std::endl;
    std::cout << "n = " << n << std::endl;
    std::cout << "m = " << m << std::endl;
    std::cout << "e = " << e << std::endl;
    std::cout << "d = " << d << std::endl;

    //Get user message, limit to 256 characters
    char message[256];
    //char* message = new char[256];
    ZeroMemory(message, 256);
    std::cout << "Enter message: ";
    std::cin.getline(message, 256);
    //Encrypt character by character(OLD) Encrypt as whole array(NEW)
    long long messageenc = encrypt((long long)message, n, e);
    std::cout << "Encrypted: " << messageenc << std::endl;
    //Decrypt character by character(OLD) Decrypt as a whole array(NEW)
    std::cout << "Decrypted: " << (char*)decrypt(messageenc, n, d) << std::endl; //Debug test to see if it worked
    std::cout << "\nEnter encryption code: ";
    long long code;
    long long newn;
    long long newd;
    std::cin >> code;
    std::cout << "Enter Key(n): ";
    std::cin >> newn;
    std::cout << "Enter Key(d): ";
    std::cin >> newd;
    std::cout << "Decrypted: " << (char*)decrypt(code, newn, newd); //decrypt it and turn it into a char pointer
    std::cin.ignore(); //Seriously this cin cleanup procedure, boi oh boi
    std::cin.clear();
    return 0;
}

int main()
{
    srand(time(NULL)); //Generate random time seed (ONLY NEEDS TO BE EXECUTED ONCE)
    std::cout << "*NOTE THAT NUMBERS MUST BE EXACTLY CORRECT OTHERWISE PROGRAM WILL CRASH*" << std::endl; //We don't need to continously spam this, so execute once
    for(;;) //Forever, to avoid calling main(); continously
    {
        actualmain();
    }
}

maybe a pro can look this over and help me with cleaning it up if it needs it

whoops removed
#include <string.h>
#include <stdlib.h>

was going to use them for something but dont recall what
« Last Edit: February 18, 2014, 08:48:50 PM by Blockzillahead »


https://www.youtube.com/watch?v=MNl3fTods9c

Such a loving glorious song.
wow
that is awesome
I don't want to stop listening to it lol
« Last Edit: February 20, 2014, 10:25:51 PM by Katadeus »

I find it hard to believe Java is the #2 most popular language. I thought it was C++.
And I thought Python only owned 3% of the market or something.


trends of how many topics on a specific language pop up
That would be a very incorrect measurement though. For example, if I search for a problem, and someone has already solved it in a topic 3 years ago, why should I make a new topic?

That would be a very incorrect measurement though. For example, if I search for a problem, and someone has already solved it in a topic 3 years ago, why should I make a new topic?

because over periods of time languages get updated and those problems have different solutions now