0xDEAD10CC Programming Challenge #1 03-03-2014, 02:52 AM
#1
*Note: This is #1 because I'm too lazy to go and change the other one.
Objective: Write a program that will take as input, a byte array, and reverse the high and low 4 bits of each 8 byte value, before using a string to cyclically change each value by the integral representation of the current char in the string. Also provide a method to reverse the action and take the encrypted text and the key to get the original text.
Example:
- Byte array: {0xAB, 0xCD, 0xEF}
- Input String (Key): "hi"
1. Reverse order: {0xBA, 0xDc, 0xFE} *I hope you can see what transformation went on for each byte value here...
2. Use input string to shift each value.
NOTE: remember 'h' = 68, and 'i' = 69
{0xBA + 'h', 0xDc + 'i', 0xFE + 'h'}
*The reason we go back to 'h' is because this is a cyclical algorithm. Once you've reached the end of the string, if you still have bytes to 'transform', then you need to go back to the beginning of the string. If the key/string is longer than the input bytes, then you'll never use the end portion of the string, and if it's the same number of characters to bytes, then obviously you'll reach the end of the string by the time you get to the last byte to be shifted by that char's value.
The result in this case leads to {0x122, 0x145, 0x166}, which is no good because these bytes values are higher than 255. Thus the same cyclical rule applies to these additions...
i.e. 256 = 0 (*because 0xFF/255 is a valid byte value, and we can't skip 0x0)
257 = 1
etc...
This ensures that we stay within the proper datatype ranges for an unsigned 8 bit integer. And with that out of the way, our result byte array should be:
{0x22, 0x45, 0x66}
If you have any questions feel free to ask. I'll post the more challenging one later, I think it might be too convoluted or too complex for the current array of programmers here yet. I'll see how people do on this one first.
Objective: Write a program that will take as input, a byte array, and reverse the high and low 4 bits of each 8 byte value, before using a string to cyclically change each value by the integral representation of the current char in the string. Also provide a method to reverse the action and take the encrypted text and the key to get the original text.
Example:
- Byte array: {0xAB, 0xCD, 0xEF}
- Input String (Key): "hi"
1. Reverse order: {0xBA, 0xDc, 0xFE} *I hope you can see what transformation went on for each byte value here...
2. Use input string to shift each value.
NOTE: remember 'h' = 68, and 'i' = 69
{0xBA + 'h', 0xDc + 'i', 0xFE + 'h'}
*The reason we go back to 'h' is because this is a cyclical algorithm. Once you've reached the end of the string, if you still have bytes to 'transform', then you need to go back to the beginning of the string. If the key/string is longer than the input bytes, then you'll never use the end portion of the string, and if it's the same number of characters to bytes, then obviously you'll reach the end of the string by the time you get to the last byte to be shifted by that char's value.
The result in this case leads to {0x122, 0x145, 0x166}, which is no good because these bytes values are higher than 255. Thus the same cyclical rule applies to these additions...
i.e. 256 = 0 (*because 0xFF/255 is a valid byte value, and we can't skip 0x0)
257 = 1
etc...
This ensures that we stay within the proper datatype ranges for an unsigned 8 bit integer. And with that out of the way, our result byte array should be:
{0x22, 0x45, 0x66}
If you have any questions feel free to ask. I'll post the more challenging one later, I think it might be too convoluted or too complex for the current array of programmers here yet. I'll see how people do on this one first.
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)