Forum: Java 34 Days Ago |
| Replies: 12 Views: 1,125 I think it probably fulfils the assignment. Note if you're not enabling any padding, you don't need to subtract 11 from the array size (the 11 was for the default padding).
Note you should never... |
Forum: Java 34 Days Ago |
| Replies: 12 Views: 1,125 You must use padding, but unless you're really sure of what you're doing, it's best to let the library do it. So just instantiate your Cipher as "RSA"-- don't specify Nopadding! |
Forum: Java Oct 18th, 2009 |
| Replies: 12 Views: 1,125 Yes.
Not necessarily. It returns a byte array containing the original data. So if you encrypt 1 byte, you'll get 256 bytes of ciphertext (with a 2048-bit key). Then, when you decrypt those... |
Forum: Java Oct 18th, 2009 |
| Replies: 12 Views: 1,125 No, not exactly although you're on the right track. If you have a 2048-bit key, then the encrypted data will be an array of 2048/8 = 256 bytes. Then, the input data can be up to 256-11=245 bytes.
... |
Forum: Java Oct 18th, 2009 |
| Replies: 12 Views: 1,125 Normally, you get the number of bits dictated by the key size (e.g. 512-bit key = 64 bytes) minus a few bytes (11, I think) of overhead. For the gory details, see the so-called PKCS #1 standard:... |
Forum: Java May 26th, 2009 |
| Replies: 8 Views: 2,114 Not sure I quite understand the problem, but if you're essentially asking "how do I turn an array of bytes into a string", you pass the array into the constructor of String. |
Forum: Java May 15th, 2009 |
| Replies: 5 Views: 488 Agree about the two ints for number of trains in UP vs DOWN direction. One thing, though-- did your tutor mention to you about thread-safety... |
Forum: Java May 9th, 2009 |
| Replies: 8 Views: 2,114 Yes, the key HAS to be of a certain length. In this case, you're asking for 128-bit encryption, so your key as to be (128/8) = 16 bytes long.
Normally, an encryption key is essentially "random"... |
Forum: Java May 9th, 2009 |
| Replies: 8 Views: 2,114 The key is simple a sequence of 16 random bytes created by the KeyGenerator. It's actually the same 16 bytes as returned by getEncoded() -- your raw[] array in this case.
If you want to use some... |
Forum: Java May 7th, 2009 |
| Replies: 4 Views: 329 Essentially, you need to make sure that whatever call is blocking is actually inside the background thread. I don't know the library you're using, but I'm guessing that the call to up.upload() is... |
Forum: Java May 4th, 2009 |
| Replies: 1 Views: 268 OK, so the basic idea is that you can use sine and cosine to convert from an angle to a position on the screen. If r is the radius, then the (x) and (y) coordinates are r * Math.sin(angle) and r *... |
Forum: Java Apr 12th, 2009 |
| Replies: 17 Views: 1,129 The key is just a string of random bytes. You can store it any which way you like-- it's just a boring old string of bytes. To actually get the bytes, you have a couple of options:
(1) Just... |
Forum: Java Apr 7th, 2009 |
| Replies: 17 Views: 1,129 As people have mentioned, you need to use asymmetric encryption at the very start of the conversation to send the sessiion key to the server. Use RSA for this. Essentially, you create a... |
Forum: Java Jan 23rd, 2009 |
| Replies: 2 Views: 248 I assume that "by threads", the assignment means sorting with several threads in parallel. So you need to:
- know how to program with threads in Java (http://www.javamex.com/tutorials/threads/)
-... |
Forum: Java Jan 8th, 2009 |
| Replies: 11 Views: 1,210 And I'd say that's a fair enough way forward. The other advantage of MD5 is that Java gives it you "out of the box".
No, I was thinking the poster could just use a standard one. Numerical... |
Forum: Java Jan 8th, 2009 |
| Replies: 11 Views: 1,210 Well, that's also true, but as a design principle, MD5 (and other "secure" hash functions) trades performance for security.
As a secure hash function, it would be totally useless. But so... |
Forum: Java Jan 5th, 2009 |
| Replies: 11 Views: 1,210 I can't see a problem with writing this in Java. For the checksums, you could look at the MessageDigest class, or just use some other fairly strong hash function. MD5 isn't necessarily the best... |
Forum: Java Jan 3rd, 2009 |
| Replies: 9 Views: 3,207 Ah, you mean convert each individual byte into an unsigned int. If that's really what the poster meant, then sorry -- I misinterpreted. But I think the poster means that they want to amalgamate the... |
Forum: Java Jan 3rd, 2009 |
| Replies: 9 Views: 3,207 Sorry, I really didn't understand "array of Byte() class" was supposed to tell the poster to do the above. I'm going to wager that they didn't either! |
Forum: Java Jan 3rd, 2009 |
| Replies: 9 Views: 3,207 You have a couple of options:
- Use the ByteBuffer (http://www.javamex.com/tutorials/io/bytebuffer.shtml) class (link is to a tutorial I wrote in case helpful), for example:
ByteBuffer bb =... |
Forum: Java Jan 3rd, 2009 |
| Replies: 2 Views: 699 If you want a literal to be a long, you need to suffix it with L:
use=1000000000L;
If the literal is small enough to fit in an int, then you can write it as an int (without the "L") and it... |
Forum: Computer Science Dec 29th, 2008 |
| Replies: 3 Views: 1,111 For more effective programming, don't try and memorise this list; bracket expressions appropriately so that any programmer can read them whether or not they have also memorised this list (practically... |
Forum: Java Dec 29th, 2008 |
| Replies: 8 Views: 638 You don't actually have to go to all that trouble, though...
int val = Integer.parseInt(str, 2);
float f = Float.intBitsToFloat(val); |
Forum: Computer Science Dec 28th, 2008 |
| Replies: 3 Views: 776 For the general case, essentially, you break the exponent down into a series of "multiply by x" and "square then multiply by x" operations. If you imagine the exponent in binary (without trailing... |
Forum: Java Dec 26th, 2008 |
| Replies: 3 Views: 560 I think I'm missing something here -- as I did when you asked a very similar thing in another thread.
If you just want to extract the substring between two character positions, then use the... |
Forum: Java Dec 22nd, 2008 |
| Replies: 6 Views: 1,718 Not sure if this is what you mean, but once you have the binary number part "0101010" etc as a string (i.e. you've stripped off the other parts of the string), to convert to an int or long, look at... |
Forum: Java Dec 20th, 2008 |
| Replies: 5 Views: 654 Erm... I wonder if the solution your instructor wanted you to get at was to just make the loop go up to 5? |
Forum: Java Dec 18th, 2008 |
| Replies: 1 Views: 370 Create a class to represent your "seg folder", then give it two String fields: name and description. |
Forum: Java Dec 17th, 2008 |
| Replies: 2 Views: 585 As the previous poster says, I think the whole point of your assignment is to demonstrate that a self-made LCG with bad parameters doesn't work very well. As well as the abovementioned link, you may... |
Forum: Java Dec 17th, 2008 |
| Replies: 7 Views: 1,392 No, it is java.nio for the ByteBuffer class. And if you're using JDK 1.4, it really should find it! Can't really suggest anything other than make sure your JDK is properly installed and that your IDE... |
Forum: Java Dec 16th, 2008 |
| Replies: 7 Views: 1,392 Look at the ByteBuffer class. You can wrap a ByteBuffer around some bytes that you need to decode, then set the byte order on the buffer to either little/big endian (or the machine's native type),... |
Forum: Java Dec 16th, 2008 |
| Replies: 2 Views: 1,459 Erm.. of course that last example is TCP, not UDP...
@bachma7 -- if you're going to cross-post to multiple forums, please have the courtesy to tell people that that's what you're doing. In your... |
Forum: Java Dec 15th, 2008 |
| Replies: 6 Views: 773 On average, you really wouldn't expect to perform so many recursions as to get a stack overflow error: even with your list size of 16,000, on average, you'd expect to go to around 14 or so levels of... |
Forum: Java Dec 15th, 2008 |
| Replies: 9 Views: 577 I have a feeling it's because you're passing in null to the constructor of MediaTracker. |
Forum: Java Dec 15th, 2008 |
| Replies: 7 Views: 563 Oh the positioning -- I think that's just because you're not actually calling the initialize() method, isn't it? |
Forum: Java Dec 15th, 2008 |
| Replies: 11 Views: 5,879 Yes, I agree with particularly the latter point -- if the thing you need to do is pick out a colour and then manipulate it, use it in various places, then Color is the right tool for the job. And... |
Forum: Java Dec 14th, 2008 |
| Replies: 9 Views: 577 The location of the source file has nothing to do with it. Either make sure the file is in the working directory from which you run the program (if you're running from the command line, that's the... |
Forum: Java Dec 14th, 2008 |
| Replies: 7 Views: 563 There's nothing wrong with it per se -- it's a very powerful component -- but it's not designed for what you're trying to do. It is designed for cases where you want to run code in some arbitrary... |
Forum: Java Dec 14th, 2008 |
| Replies: 3 Views: 945 I don't think the fact that the machine is quad core should really make any difference -- all of your stuff is executing in one thread (the GUI thread) anyway. What may make more of a difference is... |
Forum: Java Dec 14th, 2008 |
| Replies: 9 Views: 577 Erm... silly question, but are you sure the file exists...?
if you test (new File(filename)).exists(), what does it print? |