Jump to content

Byte Switcher

- - - - -

  • Please log in to reply
No replies to this topic

#1
Guest

Guest

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 3,414 posts
This is kind of pointless, but it had me entertained for a little while. This program switches all of the bytes in a file. For example, if you had a text file that said "hello world" the program would spit out "ehll oowlrd" (assuming no newline). To use in Linux, pipe in a file like this:
./byteswap <myfile >swappedfile
In Windows, I think you would type this in:
byteswap.exe <myfile >swappedfile
The program could be used to disguise files from other people, although I definitely wouldn't recommend it over encryption.
Here is the code:
#include <stdio.h>


int main()

{

	int x,y;

	while (1) {

		x=getchar();

		y=getchar();

		if (y!=EOF) {

			putchar(y);

		} else if (x!=EOF) {

			putchar(x);

			break;

		} else {

			break;

		}

		if (x!=EOF) {

			putchar(x);

		} else {

			break;

		}

	}

	return 0;

}

Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users