Post: [C++] Useful Codes (If your smart).
03-01-2011, 12:40 AM #1
kiwimoosical
Bounty hunter
(adsbygoogle = window.adsbygoogle || []).push({}); I'm bored so now every time I write or find something useful lolz.

Turn an individual bit on in some data:
    int turnBitOn(int position, int data)
{
int temp = data | (1<<position);
return temp;
}
int example = turnBitOn(4, Cool Man (aka Tustin); //24


Turn an individual bit off in some data:
    int turnBitOff(int position, int data)
{
int temp = data & ~(1<<position);
return temp;
}
int example = turnBitOff(4, 24); //8


XOR encrypt:
    typedef unsigned char* BYTEP;

bool XOREncrypt(BYTEP data, int dataLen, BYTEP key, int keyLen)
{
if(keyLen <= 0) return false;
for( unsigned int index = 0; index < dataLen; index++ )
data[index] = data[index] ^ key[index % keyLen];
return true;
}
XOREncrypt(yourData, yourDatasLength, yourSecretKey, yourSecretKeysLength);


Write to a file:
    typedef unsigned char* BYTEP;
bool Write(char* fname, BYTEP data, unsigned int dataLen, unsigned long address)
{
if(dataLen <= 0) return false;
ofstream os(fname, ios::binary);
os.seekp(ios::beg);
streamoff addresss = address;
os.seekp(addresss);
for(int x = 0; x<dataLen; ++x)
os<<data[x];
return true;
}
Write("C:\\naggers.exe", datasauce, datasaucelength, 0x69);


If you have any needs or suggestions, please post them and I'll work it out Happy

The following 2 users say thank you to kiwimoosical for this useful post:

Ritztro, TheUberFail
03-01-2011, 05:41 AM #2
Ritztro
I am a Game Developer
Pretty cool! I don't know when I will use this stuff (except for the Xor Encryption) but still looks good. Just one quick question though. Where did you learn about bits/bytes and the innerds of a computer? I know c++ pretty well but i want to be able to hardware mod and program for anything.
03-01-2011, 08:12 PM #3
kiwimoosical
Bounty hunter
Originally posted by Dutch View Post
Pretty cool! I don't know when I will use this stuff (except for the Xor Encryption) but still looks good. Just one quick question though. Where did you learn about bits/bytes and the innerds of a computer? I know c++ pretty well but i want to be able to hardware mod and program for anything.


Well, I learned from just basic computer science lessons online.
Example:
    unsigned int max = ~0;
printf(max); //0 in binary = 00000000, ~ reverses all bits in a sequence, making all bits on, 11111111, which is the max, this only gives the unsigned int's max.


Feel free to aim me if you want to learn more: Kiwimoosical
03-01-2011, 08:29 PM #4
x-MaGiiKZz-o
Who’s Jim Erased?
I understand some of them codes but not all, I am a beginner to C++ you see.
03-01-2011, 11:34 PM #5
Ritztro
I am a Game Developer
Originally posted by kiwimoosical View Post
Well, I learned from just basic computer science lessons online.
Example:
    unsigned int max = ~0;
printf(max); //0 in binary = 00000000, ~ reverses all bits in a sequence, making all bits on, 11111111, which is the max, this only gives the unsigned int's max.


Feel free to aim me if you want to learn more: Kiwimoosical


Ok so its computer science! i am going to try and go to college for that even though I am only 14 lol. Anyway ya i will Aim you (just have to set it up on ubuntu which I have to reinstall). But if you have skype: TTT_Dutch or fierce_dutch and msn is my email which I will give to you in a pm if you like.
03-01-2011, 11:53 PM #6
kiwimoosical
Bounty hunter
Originally posted by Dutch View Post
Ok so its computer science! i am going to try and go to college for that even though I am only 14 lol. Anyway ya i will Aim you (just have to set it up on ubuntu which I have to reinstall). But if you have skype: TTT_Dutch or fierce_dutch and msn is my email which I will give to you in a pm if you like.


Nice, I just turned 15, I start college classes next year at KSU and then my junior and senior year in high school (im a freshy), I get to go to tech and I get some internship because of my epic computer programming teacher <3's to him Happy

I only use aim though, so yeah, message me whenever Happy, I am free to help!
03-02-2011, 12:11 AM #7
Ritztro
I am a Game Developer
Originally posted by kiwimoosical View Post
Nice, I just turned 15, I start college classes next year at KSU and then my junior and senior year in high school (im a freshy), I get to go to tech and I get some internship because of my epic computer programming teacher <3's to him Happy

I only use aim though, so yeah, message me whenever Happy, I am free to help!


Ok I am setting up a ubuntu now so it will be a little but. Btw I am 14 and in 8th grade.. lol. I never got help back and I am part of the "smart kids". And my hs that I am going to isnt into computers at all so idk if I will get an internship. Hoping to go to Stanford though..
03-02-2011, 12:58 AM #8
kiwimoosical
Bounty hunter
Originally posted by Dutch View Post
Ok I am setting up a ubuntu now so it will be a little but. Btw I am 14 and in 8th grade.. lol. I never got help back and I am part of the "smart kids". And my hs that I am going to isnt into computers at all so idk if I will get an internship. Hoping to go to Stanford though..


Alright, just aim me when your ready Smile
03-02-2011, 02:42 AM #9
Ritztro
I am a Game Developer
Originally posted by kiwimoosical View Post
Alright, just aim me when your ready Smile


Ok, sorry its taking awhile. Ubuntu is taking a bit to install and I gtg do hw soon so hopefully I will get on.

---------- Post added at 06:42 PM ---------- Previous post was at 06:24 PM ----------

Originally posted by kiwimoosical View Post
Alright, just aim me when your ready Smile


Finally got aim working but your offline.. Hopefully we can talk tommorow!
Last edited by Ritztro ; 03-02-2011 at 02:58 AM.
03-02-2011, 09:06 PM #10
pcfreak30
>> PCFreak30.com Happy<<
I would program in c++, I just hate memory management. Prefer interpreted languages and .NET stuff. Though I get really annoyed with JAVA.

BTW, TTG_Dutch, I added you on skype Smile.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo