Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

ITT we re-do monolith.sf.net

Name: Anonymous 2007-07-24 4:27 ID:i4DLiYyV

yes, the monolith kid is retarded and his ADD-induced idea of ripping off onetime pads could never work because that's not how the law works, but that's not the point here. Here's my implementation

import qualified Data.ByteString.Lazy as B
import Data.Bits
import System.Environment

main = do
    (file1:file2:file3:_) <- getArgs
    c1 <- B.readFile file1
    c2 <- B.readFile file2
    B.writeFile file3 (B.pack (B.zipWith xor c1 (B.cycle c2)))

Name: Anonymous 2007-07-24 4:30 ID:1WqnRw/h

Needs more getopts.

Name: Anonymous 2007-07-24 4:30 ID:M/AaDFM7

Haskell is too unreadable, can you post the C code problem equivalent?

Name: Anonymous 2007-07-24 4:42 ID:Heaven

>>3
No, I'd hit the post length limit.

Name: Anonymous 2007-07-24 4:49 ID:ChXF1iJG

ITT: xoring two files to produce a third, imagining that nothing of legal interest is contained in the resulting files, and completely forgetting that no encryption at all was used.

Utterly pointless.

Therefore, epic failure.

Name: Anonymous 2007-07-24 4:52 ID:DWLhLmI/

Wow, this guy sure is a fucknut.

Name: Anonymous 2007-07-24 5:08 ID:FMx5JnE6


Things get interesting when you apply Monolith to copyrighted files. For example, munging two copyrighted files will produce a completely new file that, in most cases, contains no information from either file. In other words, the resulting Mono file is not "owned" by the original copyright holders


lawl.

Name: Anonymous 2007-07-24 5:36 ID:Heaven


int monolith_internalXORTwoFiles(
    char *inFileAPath,
    char *inFileBPath,
    char *inDestinationPath,
    int inFileNumber = 0,
    char (*inProgressHandlerFunction)( int, int, void * ) = NULL,
    void *inExtraHandlerArgument = NULL ) {
   
    FILE *fileA = fopen( inFileAPath, "rb" );

    if( fileA == NULL ) {
        return -1;
        }

   
    FILE *fileB = fopen( inFileBPath, "rb" );

    if( fileB == NULL ) {
        return -1;
        }

   
    FILE *fileOut = fopen( inDestinationPath, "wb" );

    if( fileOut == NULL ) {
        return -1;
        }

   
    char sawError = false;
    int totalBytesWritten = 0;
   
    int bufferSize = 4000;
    unsigned char *bufferA = new unsigned char[ bufferSize ];
    unsigned char *bufferB = new unsigned char[ bufferSize ];
    unsigned char *bufferOut = new unsigned char[ bufferSize ];

   
   
    char seenEndOfB = false;

   
    while( ! sawError && ! seenEndOfB ) {

        // read a block from B
        int numReadB = fread( bufferB, 1, bufferSize, fileB );

        if( numReadB > 0 ) {

            if( numReadB < bufferSize ) {
                // we have seen the end of B
                seenEndOfB = true;
                }

            // read enough bytes from A to match the bytes from B
            int numReadA =
                monolith_internalReadFileDataWrapAround( fileA, bufferA,
                                                         numReadB );

            if( numReadA == numReadB ) {

                // XOR the bytes of A and B together
                for( int i=0; i<numReadB; i++ ) {
                    bufferOut[i] = bufferA[i] ^ bufferB[i];
                    }

                // write the XORed bytes out
                int numWritten =
                    fwrite( bufferOut, 1, numReadB, fileOut );

                if( numWritten != numReadB ) {
                    sawError = true;
                    }
                else {
                    totalBytesWritten += numWritten;

                    if( inProgressHandlerFunction != NULL ) {
                        char keepGoing = inProgressHandlerFunction(
                            inFileNumber,
                            totalBytesWritten,
                            inExtraHandlerArgument );

                        if( !keepGoing ) {
                            sawError = true;
                            }
                        }
                    }
                }
            else {
                sawError = true;
                }
            }
        else {
            sawError = true;
            }
        }
       

    fclose( fileOut );
    fclose( fileA );
    fclose( fileB );

    delete [] bufferA;
    delete [] bufferB;
    delete [] bufferOut;
   
    if( sawError ) {
        return -1;
        }
    else {
        return totalBytesWritten;
        }
    }

Name: Anonymous 2007-07-24 8:08 ID:Heaven

>>8
(Post truncated.)

Name: Anonymous 2007-07-24 9:26 ID:Heaven

int main(int argc, char **argv) {
   
    FILE *fp, *fp2, *out;
    int a, b;

    if(argc != 4) return -1;
    if((fp = fopen(argv[1], "rb")) == NULL) {
        perror("fopen");
        return -1;
    }
    if((fp2 = fopen(argv[2], "rb")) == NULL) {
        perror("fopen");
        fclose(fp);
        return -1;
    }
    if((fp2 = fopen(argv[3], "w")) == NULL) {
        perror("fopen");
        fclose(fp);
        fclose(fp2);
        return -1;
    }

    while((a = getc(fp)) != EOF) {

        for(b = getc(fp2); a != EOF && b != EOF; b = getc(fp2)) {
            putc(out, a ^ b);
            a = getc(fp);
            if(a == EOF) break;
        }

        if(a != EOF) rewind(fp2);
        else break;
    }

    fcloseall();
    return 0;
}

Name: Anonymous 2009-08-16 22:33

Lain.

Name: Anonymous 2010-12-10 5:42


Don't change these.
Name: Email:
Entire Thread Thread List