Jump to content

jam08060

Member
  • Posts

    159
  • Joined

  • Last visited

Reputation Activity

  1. Like
    jam08060 got a reaction from XRaYdeR in The under 100 line challenge!   
    So I got bored and wrote an encryption program using the one-time-pad algorithm in under 100 lines.
    import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.security.SecureRandom;import java.util.Arrays;public class Leonardo { public static void main(String args[]){ FileInputStream in = null; FileOutputStream out = null; FileOutputStream keyfile = null; try { String filename = ""; //Enter file to encrypt here in = new FileInputStream(filename); out = new FileOutputStream(filename.split("\\.")[0] + "_encrypted." + filename.split("\\.")[1]); keyfile = new FileOutputStream(filename.split("\\.")[0] + "_key.txt"); int b; int index = 0; byte[] binaryContents = new byte[1024]; while((b=in.read())!=-1){ if(index >= binaryContents.length) { binaryContents = Arrays.copyOf(binaryContents, (binaryContents.length + binaryContents.length/4)); } binaryContents[index] = (byte)b; index++; } if(binaryContents.length > index) { binaryContents = Arrays.copyOf(binaryContents, index); } in.close(); SecureRandom random = new SecureRandom(); byte[] key = new byte[binaryContents.length]; random.nextBytes(key); for(int i=0; i<binaryContents.length; i++) { binaryContents[i] = (byte)(binaryContents[i] ^ key[i]); } out.write(binaryContents); keyfile.write(key); out.close(); keyfile.close(); } catch(FileNotFoundException fnfe) { System.err.println(fnfe.getMessage()); } catch(IOException ie) { System.err.println(ie.getMessage()); } finally { try { if(in != null) in.close(); if(out != null) out.close(); if(keyfile != null) keyfile.close(); } catch(IOException ie) { System.err.println(ie.getMessage()); } } }} Also, I wrote a decryption program in under 100 lines to go along with it.
    import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.Arrays;public class Michelangelo { public static void main(String args[]){ FileInputStream in = null; FileOutputStream out = null; FileInputStream key = null; try{ String filename = ""; //Enter file to be decrypted here in = new FileInputStream(filename);; out = new FileOutputStream(filename.replaceAll("_encrypted", "")); key = new FileInputStream(filename.replaceAll("_encrypted", "_key")); int b; int index = 0; byte[] binaryContents = new byte[1024]; while((b=in.read())!=-1){ if(index >= binaryContents.length) { binaryContents = Arrays.copyOf(binaryContents, (binaryContents.length + binaryContents.length / 4)); } binaryContents[index] = (byte)b; index++; } if(binaryContents.length > index) { binaryContents = Arrays.copyOf(binaryContents, index); } in.close(); byte[] keyContents = new byte[binaryContents.length]; key.read(keyContents); key.close(); for(int i=0; i<binaryContents.length; i++) { out.write((int)(binaryContents[i] ^ keyContents[i])); } out.close(); } catch(FileNotFoundException fnfe) { System.err.println(fnfe.getMessage()); } catch(IOException ie) { System.err.println(ie.getMessage()); } finally { try { if(in != null) in.close(); if(key != null) key.close(); if(out != null) out.close(); } catch(IOException ie) { System.err.println(ie.getMessage()); } } }} Enjoy!
  2. Like
    jam08060 got a reaction from Askew in Sennheiser HD 518 vs 558   
    Well I have mine in my hand... and it's not removable... so...
     
    Edit: Nvm you sir are correct, I've just discovered a new feature!
  3. Like
    jam08060 got a reaction from CaptainJolly in The under 100 line challenge!   
    So I got bored and wrote an encryption program using the one-time-pad algorithm in under 100 lines.
    import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.security.SecureRandom;import java.util.Arrays;public class Leonardo { public static void main(String args[]){ FileInputStream in = null; FileOutputStream out = null; FileOutputStream keyfile = null; try { String filename = ""; //Enter file to encrypt here in = new FileInputStream(filename); out = new FileOutputStream(filename.split("\\.")[0] + "_encrypted." + filename.split("\\.")[1]); keyfile = new FileOutputStream(filename.split("\\.")[0] + "_key.txt"); int b; int index = 0; byte[] binaryContents = new byte[1024]; while((b=in.read())!=-1){ if(index >= binaryContents.length) { binaryContents = Arrays.copyOf(binaryContents, (binaryContents.length + binaryContents.length/4)); } binaryContents[index] = (byte)b; index++; } if(binaryContents.length > index) { binaryContents = Arrays.copyOf(binaryContents, index); } in.close(); SecureRandom random = new SecureRandom(); byte[] key = new byte[binaryContents.length]; random.nextBytes(key); for(int i=0; i<binaryContents.length; i++) { binaryContents[i] = (byte)(binaryContents[i] ^ key[i]); } out.write(binaryContents); keyfile.write(key); out.close(); keyfile.close(); } catch(FileNotFoundException fnfe) { System.err.println(fnfe.getMessage()); } catch(IOException ie) { System.err.println(ie.getMessage()); } finally { try { if(in != null) in.close(); if(out != null) out.close(); if(keyfile != null) keyfile.close(); } catch(IOException ie) { System.err.println(ie.getMessage()); } } }} Also, I wrote a decryption program in under 100 lines to go along with it.
    import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.Arrays;public class Michelangelo { public static void main(String args[]){ FileInputStream in = null; FileOutputStream out = null; FileInputStream key = null; try{ String filename = ""; //Enter file to be decrypted here in = new FileInputStream(filename);; out = new FileOutputStream(filename.replaceAll("_encrypted", "")); key = new FileInputStream(filename.replaceAll("_encrypted", "_key")); int b; int index = 0; byte[] binaryContents = new byte[1024]; while((b=in.read())!=-1){ if(index >= binaryContents.length) { binaryContents = Arrays.copyOf(binaryContents, (binaryContents.length + binaryContents.length / 4)); } binaryContents[index] = (byte)b; index++; } if(binaryContents.length > index) { binaryContents = Arrays.copyOf(binaryContents, index); } in.close(); byte[] keyContents = new byte[binaryContents.length]; key.read(keyContents); key.close(); for(int i=0; i<binaryContents.length; i++) { out.write((int)(binaryContents[i] ^ keyContents[i])); } out.close(); } catch(FileNotFoundException fnfe) { System.err.println(fnfe.getMessage()); } catch(IOException ie) { System.err.println(ie.getMessage()); } finally { try { if(in != null) in.close(); if(key != null) key.close(); if(out != null) out.close(); } catch(IOException ie) { System.err.println(ie.getMessage()); } } }} Enjoy!
  4. Like
    jam08060 got a reaction from ygohome in Need a New Laptop for Programming   
    LOL.. I'm not sure you read anything I said in my previous post... also, your understanding of the developer base for C is flat out wrong.
    I could argue the developer base for C is the strongest of any language to date; the reason being is that 99% of all embedded applications are written in C.  People don't program microprocessors / microcontrollers with js, php, or ruby on rails.
    And I could argue that the market share for embedded applications is much stronger than the market share for the internet as a whole.
    There are >7Billion people on the earth (as of 2012) with an average of 1.5 devices (laptops, phones, etc...)
    This does not include vehicles, corporations, household appliances, etc...
    When you think about the many components inside each of these devices that all require code to work (sometimes thousands of components), you can clearly see the market share for C increase (99% of these programs are written in C).
     
    What you affiliate with programming is web development.
     
    I could go on here... but its not really worth the time to continue...
     
    Finally, for the majority of programming, text editors, in general, remain king not IDEs...
  5. Like
    jam08060 got a reaction from ygohome in Need a New Laptop for Programming   
    So, here is a list of features I look for in a programming notebook starting with the most important...
    8GB Ram - I find myself consistently caching around 6.5-7 GB of ram when I'm programming since I usually run a virtual machine or two and generally have a billion chrome tabs open... 1080p+ resolution display (IPS) - I hate tn panels with a passion and anything under 1080p just doesn't provide me with enough screen real estate... 128GB+ SSD - Just makes everything faster... literally... everything... boot times, program loading times, drive-thrus, lines at theme parks... everything... i5, or i7 Quad Core CPU - It doesn't really matter to me whether or not it has hyper threading, the most important part for me is having 4 real cores. Good Keyboard - DO NOT take this lightly, make sure all of the keys on the laptop you purchase are in the correct place and are the correct size for your taste.  I hate short backspace keys.  The thing that probably pissed me off the most out of any laptop I have ever owned was on a Lenovo think pad; the ctrl and the fn keys were swapped... I literally turned into the hulk every time I tried to press ctrl+c or ctrl+v and instead typed a c or a v. Ports - I would highly suggest 3-4 USB3 & USB 2 ports(or at least just USB3), an Ethernet port,  and a VGA port for connecting to external projectors at the bare minimum... Good quality headphones - I listen to music when I program, so this is a must for me... and as you can see... we have left the list of features and moved on to peripherals... Mouse - I prefer corded so I don't have to constantly change batteries and I also like having something that has a high sensitivity... but that's just my preference... Can't really think of anything else so...
    Hope this helps!
     
    Edit: Also, please note... you can program for apple devices on both Linux and Windows systems... so there's that... anyone who says otherwise is just flat out wrong lol...
  6. Like
    jam08060 got a reaction from ygohome in Need a New Laptop for Programming   
    Yes, but you will find that the majority of programmers out there use VI(M) or Emacs for 90% of their programming with the exception of programming languages like Java...
  7. Like
    jam08060 got a reaction from Nicolas in Beginner programmer here looking for help! :)   
    C and then C++ and learn OpenGL
     
    My reasoning:
    All of C is valid C++ code, so you will already be learning a good portion of C++ by learning C. C++ is pretty much the creme de la creme of Object Oriented languages when it comes to performance. OpenGL is the most widely supported graphics library and should be learned regardless of what languages you decide to learn. When learning C and C++ you will learn much more than just being able to design games, you may even discover something you would rather do than game design. I'm extremely biased toward C and C++ because I am a scientific programmer and value their flexibility and performance. Hope this helps
  8. Like
    jam08060 got a reaction from WanderingFool in Want to learn C   
    I would imagine, but pfft if people are building & using garbage collection for C++ then they are completely missing the real fun of the language!
  9. Like
    jam08060 got a reaction from WanderingFool in Want to learn C   
    I personally don't like garbage collection all that much because I much prefer controlling my own memory usage... so for my usage it is a direct replacement...
     
    This is probably because I do tend to write programs that are memory heavy multi-threaded programs and garbage collection likes to take its sweet time cleaning up memory sometimes...
  10. Like
    jam08060 got a reaction from mikeeginger in Assembly language help   
    So with assembler you are directly manipulating memory, so with the code above you are worried about the data being stored in accumulator AL.  This is because your OUT function takes the value of AL and sends it to the traffic lights.
     
    So, with that said... All your code above is doing is storing new decimal values (55, 56, 57, 58, 60, 65) into the accumulator AL and transmitting each of those values to the traffic light.
     
    From your code and the hardware you would be working with I'm not entirely sure what AA is, but it doesn't really seem to matter as it is only ever resetting the value inside AL and then being transmitted to the traffic lights, so i'd assume its probably a memory location (accumulator / register) that stores a reset or value that represents an off state... just a guess...
     
    So the main thing you need to worry about is what values you will be storing in accumulator AL to then send using the OUT instruction to the traffic lights.
     
    This should get you started, although it is a bit tricky to really give you a definitive guide without more context...
     
    Hope this helps!
  11. Like
    jam08060 got a reaction from dylandylandylan in Good headphones and Microphone?   
    Are you planning on going to lan events then? Because if you are then you don't want open headphones... you will hear the other few hundred to a thousand people in the room.
     
    If not... then I'd suggest the HD 558s, they are fantastic open headphones with a huge soundstage that really improves the gaming experience in my opinion.
     
    I'd get the HD 558s over the HD 598s as the only difference between the two is the price and that the 558s have a small piece of foam behind the drivers that is easily removable (videos all over youtube about this mod).
     
    I have a pair of HD 558s and I love them
     
    If you do plan on going to lan events then I'd suggest these since they are closed, foldable, and sound friggin awesome...
  12. Like
    jam08060 got a reaction from dylandylandylan in What headphones would you recommend?   
    Sennheiser HD 558's are also great, I prefer open headphones for gaming and with the headsets you listed I'd assume that would be your primary usage...
  13. Like
    jam08060 got a reaction from Lauen in Whats With the Beats by Dre Hate ?   
    The best headphones are stereo and not surround...
     
    Just sayin...
     
    Edit: please note... I'm not defending beats... they still sound like crap imo
  14. Like
    jam08060 got a reaction from EmoRarity in Whats With the Beats by Dre Hate ?   
    The best headphones are stereo and not surround...
     
    Just sayin...
     
    Edit: please note... I'm not defending beats... they still sound like crap imo
  15. Like
    jam08060 got a reaction from EmoRarity in Whats With the Beats by Dre Hate ?   
    roflmao still better than beats...
  16. Like
    jam08060 got a reaction from LogicDeifying in Looking for new headphones   
    So... to go back to the topic at hand...
     
    I have a pair of HD 558s and love them, and yes you can drive them with everything you already have, however they are an open style headphone and if you want to use them for mobile applications I'd suggest a closed style...
     
    The open style will leak a lot of sound and everyone around you will hear it... and if you are in a crowded room, you will still hear everyone else...
  17. Like
    jam08060 got a reaction from kinkywink in where should i start?   
    My best suggestion would be to first check out a website called W3Schools.com, they provide quick and easy tutorials for some of the basic and most widely used languages for web development today (HTML, CSS, Javascript, Python, SQL, etc.).
     
    However, if you think you'd be more interested in the more scientific programming world, you should start by learning C, C++, Java, etc.
     
    Pretty much any language you can find enough resources to learn online but if you want to get familiar with some pretty standard programming literature; O'Reilly is pretty much as standard as it gets...
     
    Depending on which rout you see yourself taking I'd suggest pursuing the following:
    Web Design -> Learn HTML & CSS and start playing around with Javascript and Python Scientific Rout -> Start learning either Java or C because these will give you the strongest "hardcore" programming base... (I like to refer to the more scientific programming style as "hardcore" as I'm slightly biased toward this...) Hope this helps!
     
     
     
    Not sure you read either post you quoted...
  18. Like
    jam08060 got a reaction from Jogostar in Thoughts On These?   
    Sennheiser = ear sex...
  19. Like
    jam08060 got a reaction from Lauen in Sennheiser HD 518 vs 558   
    Well I have mine in my hand... and it's not removable... so...
     
    Edit: Nvm you sir are correct, I've just discovered a new feature!
  20. Like
    jam08060 got a reaction from mr moose in Sennheiser HD 518 vs 558   
    Well I have mine in my hand... and it's not removable... so...
     
    Edit: Nvm you sir are correct, I've just discovered a new feature!
  21. Like
    jam08060 got a reaction from bowleggedcat in Sennheiser HD 518 vs 558   
    Well I have mine in my hand... and it's not removable... so...
     
    Edit: Nvm you sir are correct, I've just discovered a new feature!
  22. Like
    jam08060 got a reaction from ShearMe in New Equipment - Which Songs / Albums?   
    Ok, of all the GIFs i've seen... this has got to be the most random... where do people find this stuff lol?
  23. Like
    jam08060 got a reaction from MrMiniBeast in Best first language   
    Ahhh crap you sir are correct, not sure what I was thinking there 0.o
     
    I'm more of a DC fan anyway
  24. Like
    jam08060 got a reaction from alpenwasser in Best first language   
    Hi 5! Exactly!
     
    Also, if you want to learn Haskell... this is the best resource I've ever seen for it...
     
    There is a link on that page to read the text for free!
     
    Also, the text is just down right hilarious... even if you don't really care about learning the language so much... its a good all around read
  25. Like
    jam08060 got a reaction from alpenwasser in Best first language   
    Agreed, and omg I <3 Haskell... lol
     
    I'd highly suggest learning C and then C++, that way you will start off learning what benefits you will get from an imperative language, and then expanding on it by learning the Object Oriented side of things with C++...
     
    There is a really large benefit of learning C and then C++ behind it: C code is valid C++ code.
     
    So since you will have already learned C, you know the basics of C++... so from there on... you can think of C++ as an expansion of C...
     
    I love C++ because it is everything C is and more... it has all of the benefits of C and all of the benefits of being an Object Oriented Language, and doesn't fall short of Java because it doesn't have garbage collection (thank you destructors...)
     
    With that said, there can be some kinda tricky things to wrap your brain around when learning C++, however, because it would be your first or second language it may not be all that confusing because you wouldn't really have a point of reference as to why certain things work the way they do in C++...
     
    Also, I'm a very large supporter of the explicitness of actual pointers in C++ and C and not just having everything be a reference as in Java...
     
    However, with all of that said... in the words of Peter Parker... "With great power comes great responsibility..."
     
    C and C++ have no safety net and you can really break your programs if you aren't careful.
     
    While struggling without a safety net and becoming familiar with the language at first may be rough... it will be extremely beneficial because it will make you very very comfortable with debugging in the future if you decide to go on and learn other languages (mainly because other languages have way better error reporting and error handling than C and C++)
     
    So yeah, I suggest C then C++...
     
    Hope this helps...
     
    Edit: also, the books published by O'Reilley are fantastic...
×