Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd March 2019, 23:17   #1  |  Link
spoRv
Registered User
 
Join Date: Nov 2016
Posts: 114
scramble/descramble: help needed

I'd like to develop a function to scramble and descramble video; the idea is to "shuffle" video enough to let it not be (easily) recognizable.

I ended up with a simple function that divides the image in small blocks, shuffle them, invert/flip etc.

At the moment, it is VERY basic, but serves as a starting point to show how the function works:

Code:
function scramble(clip clip) {
w=clip.width/4
h=clip.height/4
clip

a01=crop(0  ,0  ,w,h).fliphorizontal
a02=crop(w  ,0  ,w,h).invert("br")
a03=crop(w*2,0  ,w,h).invert
a04=crop(w*3,0  ,0,h).turn180
a05=crop(0  ,h  ,w,h).invert
a06=crop(w  ,h  ,w,h).flipvertical
a07=crop(w*2,h  ,w,h).invert
a08=crop(w*3,h  ,0,h).invert("rg")
a09=crop(0  ,h*2,w,h).swapuv
a10=crop(w  ,h*2,w,h).turn180	
a11=crop(w*2,h*2,w,h).swapuv	
a12=crop(w*3,h*2,0,h).turn180
a13=crop(0  ,h*3,w,0).swapuv
a14=crop(w  ,h*3,w,0).invert("gb")
a15=crop(w*2,h*3,w,0).flipvertical
a16=crop(w*3,h*3,0,0).fliphorizontal

stackvertical(\
stackhorizontal(a12,a05,a08,a15),\
stackhorizontal(a06,a10,a01,a09),\
stackhorizontal(a11,a16,a14,a04),\
stackhorizontal(a03,a13,a07,a02))
}
Code:
function descramble(clip clip) {
w=clip.width/4
h=clip.height/4
clip

a01=crop(0  ,0  ,w,h)
a02=crop(w  ,0  ,w,h)
a03=crop(w*2,0  ,w,h)
a04=crop(w*3,0  ,0,h)
a05=crop(0  ,h  ,w,h)
a06=crop(w  ,h  ,w,h)
a07=crop(w*2,h  ,w,h)
a08=crop(w*3,h  ,0,h)
a09=crop(0  ,h*2,w,h)
a10=crop(w  ,h*2,w,h)
a11=crop(w*2,h*2,w,h)
a12=crop(w*3,h*2,0,h)
a13=crop(0  ,h*3,w,0)
a14=crop(w  ,h*3,w,0)
a15=crop(w*2,h*3,w,0)
a16=crop(w*3,h*3,0,0)

stackvertical(\
stackhorizontal(a07,a16,a13,a12),\
stackhorizontal(a02,a05,a15,a03),\
stackhorizontal(a08,a06,a09,a01),\
stackhorizontal(a14,a11,a04,a10))

a01=crop(0  ,0  ,w,h).fliphorizontal
a02=crop(w  ,0  ,w,h).invert("br")
a03=crop(w*2,0  ,w,h).invert
a04=crop(w*3,0  ,0,h).turn180
a05=crop(0  ,h  ,w,h).invert
a06=crop(w  ,h  ,w,h).flipvertical
a07=crop(w*2,h  ,w,h).invert
a08=crop(w*3,h  ,0,h).invert("rg")
a09=crop(0  ,h*2,w,h).swapuv
a10=crop(w  ,h*2,w,h).turn180	
a11=crop(w*2,h*2,w,h).swapuv	
a12=crop(w*3,h*2,0,h).turn180
a13=crop(0  ,h*3,w,0).swapuv
a14=crop(w  ,h*3,w,0).invert("gb")
a15=crop(w*2,h*3,w,0).flipvertical
a16=crop(w*3,h*3,0,0).fliphorizontal

stackvertical(\
stackhorizontal(a01,a02,a03,a04),\
stackhorizontal(a05,a06,a07,a08),\
stackhorizontal(a09,a10,a11,a12),\
stackhorizontal(a13,a14,a15,a16))
}
What I'd like to reach is the following:

- input a N number, where the image will be divided in N x N parts - I guess N <= 16 is enough
- input a string with N triplets, where first character is the X, second is the Y, and third is the type of "manipulation" of that given sector (like, for example, V = flipvertical, I = invert etc. and of course a combination of more than a single one)
- possibly get a random string with a further function

I know that it's possible to use scriptclip to reiterate the stacking, and midstr to get the string triplets, but I do not know how to put them in use!

Note: it works with uncompressed/lossless video, I'm pretty sure it will NOT work with lossy video.

If someone has a better/different way to reach the target - shuffle the image as much as possible, getting the file size not so much bigger - it will be great!

As usual, thanks in advance to anybody can help!
spoRv is offline   Reply With Quote
Old 3rd March 2019, 10:35   #2  |  Link
jmartinr
Registered User
 
jmartinr's Avatar
 
Join Date: Dec 2007
Location: Enschede, NL
Posts: 295
Maybe it's a better idea to xor everything with the the values of _one_ still picture. That still picture must be filled with random noise.

You could still discern motion from non-motion after that. But at least it should be fast and workable.
__________________
Roelofs Coaching

Last edited by jmartinr; 3rd March 2019 at 11:05. Reason: Clarification
jmartinr is offline   Reply With Quote
Old 4th March 2019, 18:34   #3  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 1,050
This seems to do what you want, at least the basic logic for that: https://github.com/kewenyu/BlockEval...or-Vapoursynth
Come to the bright side...
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth
VapourSynth Portable FATPACK || VapourSynth Database || https://github.com/avisynth-repository
ChaosKing is offline   Reply With Quote
Old 11th March 2019, 05:52   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,372
spoRv,
something to play with, Shuffle v0.00:- LINK REMOVED, See Here:- https://forum.doom9.org/showthread.p...92#post1868592


Code:
# Stack Overhead Subtitle Text, with optional FrameNumber shown.
Function TSub(clip c,string Tit,Bool "ShowFrameNo",Int "Col"){
    c.BlankClip(height=20,Color=Default(Col,0))
    (Default(ShowFrameNo,False))?ScriptClip("""Subtitle(String(current_frame,"%.f] """+Tit+""""))"""):Trim(0,-1).Subtitle(Tit)
    Return StackVertical(c).AudioDubEx(c)
}

/*

    ShuffleV(clip c, Int "Seed"=0 , Int "blkH"=8 , Bool "Interlaced"=False , Bool "Inverse"=False )                # Vertical   Shuffle
    ShuffleH(clip c, Int "Seed"=0 , Int "blkW"=8 , Bool "Inverse"=False )                                          # Horizontal Shuffle

*/

LoadPlugin(".\Shuffle.dll")
#LoadPlugin(".\Shuffle_x64.dll")

SECRET_KEY_H = 123456789        # EDIT: I should perhaps have called this one SECRET_KEY_V Vertical Shuffle
SECRET_KEY_W = 987654321        # EDIT: I should perhaps have called this one SECRET_KEY_H Horizontal Shuffle

AviSource("D:\Parade.avi")
Crop(0,0,Width/8*8,Height/8*8)      # Can Crop or AddBorders to achieve required Width/Height BlkW/H

ConvertToYV12
#ConvertToYV16
#ConvertToYV24
#ConvertToYV411
#ConvertToY8

ORG=Last

BlkH=8                  # Blks for Vertial Shuffle
BlkW=8                  # Blks for Horizontal Shuffle
INTERLACED=False        # Doubles minimum required ShuffleV BlkH, eg YV12 interlaced requires multiple of 4 when INTERLACED=True, else 2

ShuffleV(seed=SECRET_KEY_H,blkH=BLKH,Interlaced=INTERLACED)                 # Shuffle Vertical blocks
#Return Last
ShuffleH(seed=SECRET_KEY_W,blkW=BLKW)                                       # Shuffle Horizontal blocks
#Return Last
SHUFFLED=Last

ShuffleV(seed=SECRET_KEY_H,blkH=BLKH,Interlaced=INTERLACED,Inverse=True)    # Inverse: De-Shuffle V/H, Order does not matter
ShuffleH(seed=SECRET_KEY_W,blkW=BLKW,Inverse=True)
#Return Last

StackHorizontal(SHUFFLED.TSub("Shuffled"+String(BlkH," BlkH=%.0f")+String(BlkW," BlkW=%.0f"),true),Last.TSub("De-Shuffled"))
#ConvertToRGB32
8x8


2x2


Have Not tried at all to compress, but likely a lot better than the XOR stuff (so long as BlkW,blkH not so small).

EDIT: Of course you can still do whatever flipping etc you want, just need to unmagle in reverse order.

EDIT: Seed as for The XOR thing, 0 = ALWAYS SAME, -1 = based on system Uptime, Ie not reversable, else user seed which is reversable.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 12th March 2019 at 23:16.
StainlessS is offline   Reply With Quote
Old 11th March 2019, 07:48   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,372
OK, here some image samples after shuffle and compress and then de-compress De-shuffle again.
Compressed @ CRF 21.5, Slow.

Looks a whole lot better than XOR-ing

4x4 shuffle block sizes [EDIT: Seems to have been de-saturated a bit]


Next two did AddBorders instead of crop, thats the grey border.
8x8


16x16


Shuffled @ 24x24 (I used Addborders instead of crop, I did not try compress).


Time for bed.

EDIT: Note original 22MB size was YouTube compressed, so would likely need to be compressed somewhat bigger anyways.

EDIT: Basic Addborders Shuffler
Code:
# Stack Overhead Subtitle Text, with optional FrameNumber shown.
Function TSub(clip c,string Tit,Bool "ShowFrameNo",Int "Col"){
    c.BlankClip(height=20,Color=Default(Col,0))
    (Default(ShowFrameNo,False))?ScriptClip("""Subtitle(String(current_frame,"%.f] """+Tit+""""))"""):Trim(0,-1).Subtitle(Tit)
    Return StackVertical(c).AudioDubEx(c)
}

/*

    ShuffleV(clip c, Int "Seed"=0 , Int "blkH"=8 , Bool "Interlaced"=False , Bool "Inverse"=False )                # Vertical   Shuffle
    ShuffleH(clip c, Int "Seed"=0 , Int "blkW"=8 , Bool "Inverse"=False )                                          # Horizontal Shuffle

*/

LoadPlugin(".\Shuffle.dll")
#LoadPlugin(".\Shuffle_x64.dll")

SECRET_KEY_H = 123456789
SECRET_KEY_W = 987654321
BlkH=8                  # Blks for Vertial Shuffle
BlkW=8                 # Blks for Horizontal Shuffle
INTERLACED=False        # Doubles minimum required ShuffleV BlkH, eg YV12 interlaced requires multiple of 4 when INTERLACED=True, else 2

AviSource("D:\Parade.avi")
#Crop(0,0,Width/8*8,Height/8*8)      # Can Crop or AddBorders to achieve required Width/Height BlkW/H


H=Height % BLKH
W=Width  % BLKW
(W!=0 || H!=0) ? AddBorders(0,0,BlkW-W,BlkH-H,$808080) : NOP


ConvertToYV12
#ConvertToYV16
#ConvertToYV24
#ConvertToYV411
#ConvertToY8

ORG=Last


ShuffleV(seed=SECRET_KEY_H,blkH=BLKH,Interlaced=INTERLACED)                 # Shuffle Vertical blocks
#Return Last
ShuffleH(seed=SECRET_KEY_W,blkW=BLKW)                                       # Shuffle Horizontal blocks
Return Last.TSub("Shuffled 24x24",true)
SHUFFLED=Last

ShuffleV(seed=SECRET_KEY_H,blkH=BLKH,Interlaced=INTERLACED,Inverse=True)    # Inverse: De-Shuffle V/H, Order does not matter
ShuffleH(seed=SECRET_KEY_W,blkW=BLKW,Inverse=True)
#Return Last

#SHUFFLED=SHUFFLED.TSub("Shuffled"+String(BlkH," BlkH=%.0f")+String(BlkW," BlkW=%.0f"),true)
#Last=Last.TSub("De-Shuffled")

StackHorizontal(SHUFFLED,Last)
#ConvertToRGB32
Basic Addborders De-Shuffler
Code:
# Stack Overhead Subtitle Text, with optional FrameNumber shown.
Function TSub(clip c,string Tit,Bool "ShowFrameNo",Int "Col"){
    c.BlankClip(height=20,Color=Default(Col,0))
    (Default(ShowFrameNo,False))?ScriptClip("""Subtitle(String(current_frame,"%.f] """+Tit+""""))"""):Trim(0,-1).Subtitle(Tit)
    Return StackVertical(c).AudioDubEx(c)
}

/*

    ShuffleV(clip c, Int "Seed"=0 , Int "blkH"=8 , Bool "Interlaced"=False , Bool "Inverse"=False )                # Vertical   Shuffle
    ShuffleH(clip c, Int "Seed"=0 , Int "blkW"=8 , Bool "Inverse"=False )                                          # Horizontal Shuffle

*/

LoadPlugin(".\Shuffle.dll")
#LoadPlugin(".\Shuffle_x64.dll")

SECRET_KEY_H = 123456789
SECRET_KEY_W = 987654321
BlkH=8                  # Blks for Vertial Shuffle
BlkW=8                  # Blks for Horizontal Shuffle
INTERLACED=False        # Doubles minimum required ShuffleV BlkH, eg YV12 interlaced requires multiple of 4 when INTERLACED=True, else 2

AviSource("D:\Parade.avi")
H=Height % BLKH
W=Width  % BLKW
(W!=0 || H!=0) ? AddBorders(0,0,BlkW-W,BlkH-H,$808080) : NOP
ORIG=Last
#Return Last
AviSource(".\8x8.avi")
#Return Last

ConvertToYV12
ORG=Last


ShuffleH(seed=SECRET_KEY_W,blkW=BLKW,Inverse=True)
ShuffleV(seed=SECRET_KEY_H,blkH=BLKH,Interlaced=INTERLACED,Inverse=True)    # Inverse: De-Shuffle V/H, Order does not matter
#Return Last

ORIG=ORIG.TSub("Original  mp4 size=22MB",true)
Last=Last.TSub("UnShuffled 8x8 mp4 size=153MB")

StackHorizontal(ORIG,Last)
#ConvertToRGB32
Really time for bed.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th March 2019 at 03:04.
StainlessS is offline   Reply With Quote
Old 11th March 2019, 08:55   #6  |  Link
spoRv
Registered User
 
Join Date: Nov 2016
Posts: 114
Thanks StainlessS, as always your help is really appreciated, and you are able so solve everything!



I modified my previous functions, including your shaffle ones; yes, blocks are quite big as default, but when compressed (lossless), the shuffled version is only about 4% bigger than the original - while using smaller blocks, let's say 8, it would be more than 20% bigger - and it's more... well, shuffled than your shuffled ones!

Code:
function scramble(clip clip, Int "Seed" , Int "blk") {
# need Shuffle plugin by StainlessS: https://forum.doom9.org/showthread.php?p=1868592
seed = default(seed, 123456789)
blk  = default(blk, 120)
w    = clip.width/4
h    = clip.height/4

clip

a01=crop(0  ,0  ,w,h).fliphorizontal.invert
a02=crop(w  ,0  ,w,h).invert("br")
a03=crop(w*2,0  ,w,h).invert
a04=crop(w*3,0  ,0,h).turn180.invert
a05=crop(0  ,h  ,w,h).invert
a06=crop(w  ,h  ,w,h).flipvertical.invert
a07=crop(w*2,h  ,w,h).invert
a08=crop(w*3,h  ,0,h).invert("rg")
a09=crop(0  ,h*2,w,h).swapuv
a10=crop(w  ,h*2,w,h).turn180
a11=crop(w*2,h*2,w,h).flipvertical.swapuv
a12=crop(w*3,h*2,0,h).turn180
a13=crop(0  ,h*3,w,0).swapuv
a14=crop(w  ,h*3,w,0).invert("gb")
a15=crop(w*2,h*3,w,0).flipvertical.invert
a16=crop(w*3,h*3,0,0).fliphorizontal.invert

stackvertical(\
stackhorizontal(a12,a05,a08,a15),\
stackhorizontal(a06,a10,a01,a09),\
stackhorizontal(a11,a16,a14,a04),\
stackhorizontal(a03,a13,a07,a02))

Shuffle2D(seed=seed,blkW=blk,blkH=blk)
}
Code:
function descramble(clip clip, Int "Seed" , Int "blk") {
# need Shuffle plugin by StainlessS: https://forum.doom9.org/showthread.php?p=1868592
seed= default(seed, 123456789)
blk = default(blk, 120) 
w    = clip.width/4
h    = clip.height/4

clip

Shuffle2D(seed=seed,blkW=blk,blkH=blk,Inverse=True)  

a01=crop(0  ,0  ,w,h)
a02=crop(w  ,0  ,w,h)
a03=crop(w*2,0  ,w,h)
a04=crop(w*3,0  ,0,h)
a05=crop(0  ,h  ,w,h)
a06=crop(w  ,h  ,w,h)
a07=crop(w*2,h  ,w,h)
a08=crop(w*3,h  ,0,h)
a09=crop(0  ,h*2,w,h)
a10=crop(w  ,h*2,w,h)
a11=crop(w*2,h*2,w,h)
a12=crop(w*3,h*2,0,h)
a13=crop(0  ,h*3,w,0)
a14=crop(w  ,h*3,w,0)
a15=crop(w*2,h*3,w,0)
a16=crop(w*3,h*3,0,0)

stackvertical(\
stackhorizontal(a07,a16,a13,a12),\
stackhorizontal(a02,a05,a15,a03),\
stackhorizontal(a08,a06,a09,a01),\
stackhorizontal(a14,a11,a04,a10))

a01=crop(0  ,0  ,w,h).fliphorizontal.invert
a02=crop(w  ,0  ,w,h).invert("br")
a03=crop(w*2,0  ,w,h).invert
a04=crop(w*3,0  ,0,h).turn180.invert
a05=crop(0  ,h  ,w,h).invert
a06=crop(w  ,h  ,w,h).flipvertical.invert
a07=crop(w*2,h  ,w,h).invert
a08=crop(w*3,h  ,0,h).invert("rg")
a09=crop(0  ,h*2,w,h).swapuv
a10=crop(w  ,h*2,w,h).turn180
a11=crop(w*2,h*2,w,h).flipvertical.swapuv
a12=crop(w*3,h*2,0,h).turn180
a13=crop(0  ,h*3,w,0).swapuv
a14=crop(w  ,h*3,w,0).invert("gb")
a15=crop(w*2,h*3,w,0).flipvertical.invert
a16=crop(w*3,h*3,0,0).fliphorizontal.invert

stackvertical(\
stackhorizontal(a01,a02,a03,a04),\
stackhorizontal(a05,a06,a07,a08),\
stackhorizontal(a09,a10,a11,a12),\
stackhorizontal(a13,a14,a15,a16))
}

Last edited by spoRv; 13th March 2019 at 03:12. Reason: replaced previous ShuffleH/V with Shuffle2D
spoRv is offline   Reply With Quote
Old 11th March 2019, 14:45   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,372
I'll have a go at a 2D shuffler next, better disguise, but might require a bit more bitrate {not so very much, I hope) .

EDIT: 2 x 1D not same as 1 x 2D.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 11th March 2019 at 15:00.
StainlessS is offline   Reply With Quote
Old 11th March 2019, 20:44   #8  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 219
I wonder if using Burrows-Wheeler transform would make it compress better. You could use it for the individual blocks or just once for the whole frame. I don't know how it will reverse after compression artifacts though...
zorr is offline   Reply With Quote
Old 12th March 2019, 14:47   #9  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,372
Quote:
I wonder if using Burrows-Wheeler transform would make it compress better
Yeh, that might actually work, at least when 2x2 shuffle [or even 1x1 shuffle when combine U and V together with Y in single plane Y8 (U & V horizontal Stacked) below Y],
but think maybe would have to compress via TIFF or something similar ie run-length encoding, maybe x264 would mess up for inverse Burrows-Wheeler though.

Was recently playing with a Primes generator (gen'ed all primes below 1 Billion in about 1 Minute, on my crap machine).
Generated ~80,000 pages of primes where 64 lines per page and 10 primes per line.

Here some of my new favourite Primes
Code:
$ABADA55
$1BDEAD
$DEADED
$BEEEFFF
$BEEFBAD
$BEEFA55
$BEEFC0D
The SieveOfSundaram code published on GeeksForGeeks has a problem where the number below which to print all primes is 65536 or more,
where Primes printed will be wrong (because 32768 ($8000) squared produces -ve int and starts messing up the table of known primes/non-primes.

Here mod of the code to produce paginated output
Code:
// C++ program to print primes smaller than n using Sieve of Sundaram.
#include <windows.h>
#include <stdio.h>
#include <ctype.h>

// Will fail where n about 65536 and over
// Will (go -ve) if using type int where eg (i + j + 2*i*j) and i>=32768 and j>=32768, will go -ve
#define INT _int64 // EDIT: Fixes problem

// Prints all prime numbers smaller than n
void SieveOfSundaram(int n,int PrimesPerLine, int LinesPerPage,bool Hex) {
    int PrimesPerPage=PrimesPerLine*LinesPerPage;
    // In general Sieve of Sundaram, produces primes smaller or equal to (2*x + 2) for a given number x.
    // Since we want primes smaller than n, we reduce n to half
    INT nNew = (n-2)/2;     // EDIT: This fixes above problem.

    // This array is used to separate numbers of the form i+j+2ij from others where  1 <= i <= j
    bool *marked = new bool[nNew + 1];
    if(marked==NULL) {
        perror("Error alloc buffer");
        exit(-2);
    }

    // Initalize all elements as not marked
    for(int m=0; m <= nNew ; ++m)
        marked[m] = false;

    // Main logic of Sundaram.  Mark all numbers of the
    // form i + j + 2ij as true where 1 <= i <= j
    for (INT i=1; i <= nNew; ++i) {
        for (INT j=i; (i + j + 2*i*j) <= nNew; j++) {
            INT q=i + j + 2*i*j;
/*
            if(q < 0) {
                printf("-ve i=%d j=%d q=%d\n",i,j,q);
                goto out;
            }
*/
            marked[q] = true;
        }
    }

out:
    int page  = 0;
    int cnt   = 0;
    INT prime = 0;
    if(n > 2) {
        printf("\n\n                       Primes Page No %d\n",++page);
        ++cnt;
        prime = 2;
        printf("\n%4d)    ",cnt);
        if(Hex)     { printf("$%-9X",prime); }
        else        { printf("%-11d",prime); }
        for(INT i=1 ; i<=nNew ; ++i) {
            if (marked[i] == false) {
                ++cnt;
                prime = 2*i + 1;
                if(cnt % PrimesPerPage==1) {
                    printf("\n\n                       Primes Page No %d\n",++page);
                }
                if(cnt % PrimesPerLine ==1)
                    printf("\n%4d)    ",cnt);

                if(Hex) { printf("$%-9X", prime); }
                else    { printf("%-11d", prime); }
            }
        }
        printf("\n");
    }
    delete [] marked;
}

// Driver program to test above

#define PRIMES_PER_LINE 10
#define LINES_PER_PAGE  64
#define HEX             false

int main( int argc, const char* argv[] ) {
    int n = 1000001
;
    int PrimesPerLine=PRIMES_PER_LINE;
    int LinesPerPage=LINES_PER_PAGE;
    bool Hex=HEX;
//  bool usage=(argc==1);
    bool usage=false;
    for(int i=1; usage==false && i<argc; i++) {
        if (argv[i][0] == '-') {
            if (argv[i][1] == 'w' || argv[i][1] == 'W') {
                PrimesPerLine=atoi(&argv[++i][0]);
            } else if (argv[i][1] == 'l' || argv[i][1] == 'L') {
                LinesPerPage=atoi(&argv[++i][0]);
            } else if (argv[i][1] == 'h' || argv[i][1] == 'H') {
                Hex=true;
            } else {
                printf("Invalid Option");
                usage=true;
            }
        } else if (argv[i][0]=='$') {
            char *stopstring;
            n=strtol(&argv[i][1],&stopstring,16);
        } else if (isdigit(argv[i][0])) {
            n=atoi(&argv[i][0]);
        } else {
            //usage=true;
        }
    }
    if(usage) {
        printf("Usage: %s n [-W Width] [-L Lines] [-h]\n",argv[0]);
        printf("   Where:-\n");
        printf("     n, number below which all primes are printed.\n");
        printf("     Width, Primes per line across the page.\n");
        printf("     Lines, Lines per page.\n");
        printf("     -h switches on Hex Primes.\n");
        return -1;
    }
    printf("Number        = %d ($%X)\n",n,n);
    printf("PrimesPerLine = %d\n",PrimesPerLine);
    printf("LinesPerPage  = %d\n",LinesPerPage);
    printf("Hex           = %s\n",(Hex)?"True":"False");
    SieveOfSundaram(n,PrimesPerLine,LinesPerPage,Hex);
    return 0;
}
By default prints all primes below 1000001, 123 Pages.
Use eg
Code:
D:\>sieveofsundaram >Primes.txt
D:\>sieveofsundaram 1000000001 -h >HexPrimes.txt # all primes below 1 billion and 1, and print them in hex
Executable here:- http://www.mediafire.com/file/3fzq69...ndaram.7z/file
EDIT: Dont go over about 4 billion else same problem as already noted.

Got the 2D Shuffler working just fine, doing some encodes and stuff and post in new thread soon.

EDIT: Last Partial page where printing primes below 1,000,000,001 in hex (the produced 560MB opens OK in NotePad++ x64)
Code:
                       Primes Page No 79450

50847361)    $3B9ABB3F $3B9ABB43 $3B9ABB57 $3B9ABB63 $3B9ABB6D $3B9ABB8D $3B9ABB93 $3B9ABB97 $3B9ABB9D $3B9ABBA9 
50847371)    $3B9ABBB5 $3B9ABBC7 $3B9ABBDF $3B9ABBF7 $3B9ABC35 $3B9ABC4D $3B9ABC7D $3B9ABCAB $3B9ABCC3 $3B9ABCE3 
50847381)    $3B9ABCE9 $3B9ABCFF $3B9ABD05 $3B9ABD11 $3B9ABD23 $3B9ABD25 $3B9ABD37 $3B9ABD4D $3B9ABD6B $3B9ABD9B 
50847391)    $3B9ABDE5 $3B9ABDF1 $3B9ABDF7 $3B9ABE37 $3B9ABE3D $3B9ABE5D $3B9ABE79 $3B9ABE8B $3B9ABE99 $3B9ABEAB 
50847401)    $3B9ABECD $3B9ABEFD $3B9ABF35 $3B9ABF39 $3B9ABF41 $3B9ABF53 $3B9ABF5F $3B9ABF75 $3B9ABF7D $3B9ABF93 
50847411)    $3B9ABFAD $3B9ABFDB $3B9AC011 $3B9AC031 $3B9AC067 $3B9AC079 $3B9AC07F $3B9AC083 $3B9AC089 $3B9AC095 
50847421)    $3B9AC0BB $3B9AC0C7 $3B9AC0CB $3B9AC0E9 $3B9AC0EF $3B9AC101 $3B9AC115 $3B9AC149 $3B9AC14B $3B9AC15B 
50847431)    $3B9AC161 $3B9AC173 $3B9AC1AF $3B9AC1C3 $3B9AC20F $3B9AC233 $3B9AC241 $3B9AC247 $3B9AC26B $3B9AC281 
50847441)    $3B9AC29B $3B9AC2A7 $3B9AC2B9 $3B9AC2BD $3B9AC2BF $3B9AC2C3 $3B9AC2DD $3B9AC2E7 $3B9AC2FB $3B9AC323 
50847451)    $3B9AC335 $3B9AC33D $3B9AC365 $3B9AC383 $3B9AC3A1 $3B9AC3D7 $3B9AC3FB $3B9AC425 $3B9AC42B $3B9AC42D 
50847461)    $3B9AC445 $3B9AC449 $3B9AC463 $3B9AC491 $3B9AC499 $3B9AC49D $3B9AC4A3 $3B9AC4AF $3B9AC4B1 $3B9AC4BD 
50847471)    $3B9AC4C7 $3B9AC4DB $3B9AC4DF $3B9AC4E1 $3B9AC4E5 $3B9AC539 $3B9AC545 $3B9AC551 $3B9AC57B $3B9AC58F 
50847481)    $3B9AC595 $3B9AC5B7 $3B9AC5C5 $3B9AC5C9 $3B9AC5D1 $3B9AC5ED $3B9AC5EF $3B9AC5FB $3B9AC605 $3B9AC619 
50847491)    $3B9AC629 $3B9AC635 $3B9AC643 $3B9AC653 $3B9AC65B $3B9AC67F $3B9AC683 $3B9AC689 $3B9AC69B $3B9AC6A1 
50847501)    $3B9AC6AF $3B9AC6BB $3B9AC6CD $3B9AC6D7 $3B9AC6D9 $3B9AC6DD $3B9AC6F7 $3B9AC6FD $3B9AC75B $3B9AC769 
50847511)    $3B9AC779 $3B9AC79F $3B9AC7C9 $3B9AC7FF $3B9AC803 $3B9AC80F $3B9AC827 $3B9AC835 $3B9AC863 $3B9AC86F 
50847521)    $3B9AC877 $3B9AC87D $3B9AC8B3 $3B9AC8BD $3B9AC8F5 $3B9AC8FB $3B9AC907 $3B9AC90D $3B9AC911 $3B9AC935 
50847531)    $3B9AC98B $3B9AC995 $3B9AC9B9 $3B9AC9C1
EDIT: And 1st page in Decimal
Code:
Number        = 1000001 ($F4241)
PrimesPerLine = 10
LinesPerPage  = 64
Hex           = False


                       Primes Page No 1

   1)    2          3          5          7          11         13         17         19         23         29         
  11)    31         37         41         43         47         53         59         61         67         71         
  21)    73         79         83         89         97         101        103        107        109        113        
  31)    127        131        137        139        149        151        157        163        167        173        
  41)    179        181        191        193        197        199        211        223        227        229        
  51)    233        239        241        251        257        263        269        271        277        281        
  61)    283        293        307        311        313        317        331        337        347        349        
  71)    353        359        367        373        379        383        389        397        401        409        
  81)    419        421        431        433        439        443        449        457        461        463        
  91)    467        479        487        491        499        503        509        521        523        541        
 101)    547        557        563        569        571        577        587        593        599        601        
 111)    607        613        617        619        631        641        643        647        653        659        
 121)    661        673        677        683        691        701        709        719        727        733        
 131)    739        743        751        757        761        769        773        787        797        809        
 141)    811        821        823        827        829        839        853        857        859        863        
 151)    877        881        883        887        907        911        919        929        937        941        
 161)    947        953        967        971        977        983        991        997        1009       1013       
 171)    1019       1021       1031       1033       1039       1049       1051       1061       1063       1069       
 181)    1087       1091       1093       1097       1103       1109       1117       1123       1129       1151       
 191)    1153       1163       1171       1181       1187       1193       1201       1213       1217       1223       
 201)    1229       1231       1237       1249       1259       1277       1279       1283       1289       1291       
 211)    1297       1301       1303       1307       1319       1321       1327       1361       1367       1373       
 221)    1381       1399       1409       1423       1427       1429       1433       1439       1447       1451       
 231)    1453       1459       1471       1481       1483       1487       1489       1493       1499       1511       
 241)    1523       1531       1543       1549       1553       1559       1567       1571       1579       1583       
 251)    1597       1601       1607       1609       1613       1619       1621       1627       1637       1657       
 261)    1663       1667       1669       1693       1697       1699       1709       1721       1723       1733       
 271)    1741       1747       1753       1759       1777       1783       1787       1789       1801       1811       
 281)    1823       1831       1847       1861       1867       1871       1873       1877       1879       1889       
 291)    1901       1907       1913       1931       1933       1949       1951       1973       1979       1987       
 301)    1993       1997       1999       2003       2011       2017       2027       2029       2039       2053       
 311)    2063       2069       2081       2083       2087       2089       2099       2111       2113       2129       
 321)    2131       2137       2141       2143       2153       2161       2179       2203       2207       2213       
 331)    2221       2237       2239       2243       2251       2267       2269       2273       2281       2287       
 341)    2293       2297       2309       2311       2333       2339       2341       2347       2351       2357       
 351)    2371       2377       2381       2383       2389       2393       2399       2411       2417       2423       
 361)    2437       2441       2447       2459       2467       2473       2477       2503       2521       2531       
 371)    2539       2543       2549       2551       2557       2579       2591       2593       2609       2617       
 381)    2621       2633       2647       2657       2659       2663       2671       2677       2683       2687       
 391)    2689       2693       2699       2707       2711       2713       2719       2729       2731       2741       
 401)    2749       2753       2767       2777       2789       2791       2797       2801       2803       2819       
 411)    2833       2837       2843       2851       2857       2861       2879       2887       2897       2903       
 421)    2909       2917       2927       2939       2953       2957       2963       2969       2971       2999       
 431)    3001       3011       3019       3023       3037       3041       3049       3061       3067       3079       
 441)    3083       3089       3109       3119       3121       3137       3163       3167       3169       3181       
 451)    3187       3191       3203       3209       3217       3221       3229       3251       3253       3257       
 461)    3259       3271       3299       3301       3307       3313       3319       3323       3329       3331       
 471)    3343       3347       3359       3361       3371       3373       3389       3391       3407       3413       
 481)    3433       3449       3457       3461       3463       3467       3469       3491       3499       3511       
 491)    3517       3527       3529       3533       3539       3541       3547       3557       3559       3571       
 501)    3581       3583       3593       3607       3613       3617       3623       3631       3637       3643       
 511)    3659       3671       3673       3677       3691       3697       3701       3709       3719       3727       
 521)    3733       3739       3761       3767       3769       3779       3793       3797       3803       3821       
 531)    3823       3833       3847       3851       3853       3863       3877       3881       3889       3907       
 541)    3911       3917       3919       3923       3929       3931       3943       3947       3967       3989       
 551)    4001       4003       4007       4013       4019       4021       4027       4049       4051       4057       
 561)    4073       4079       4091       4093       4099       4111       4127       4129       4133       4139       
 571)    4153       4157       4159       4177       4201       4211       4217       4219       4229       4231       
 581)    4241       4243       4253       4259       4261       4271       4273       4283       4289       4297       
 591)    4327       4337       4339       4349       4357       4363       4373       4391       4397       4409       
 601)    4421       4423       4441       4447       4451       4457       4463       4481       4483       4493       
 611)    4507       4513       4517       4519       4523       4547       4549       4561       4567       4583       
 621)    4591       4597       4603       4621       4637       4639       4643       4649       4651       4657       
 631)    4663       4673       4679       4691       4703       4721       4723       4729       4733       4751
EDIT: LINK REMOVED and opened new Thread for Shuffle:- https://forum.doom9.org/showthread.p...92#post1868592
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 12th March 2019 at 23:17.
StainlessS is offline   Reply With Quote
Old 13th March 2019, 03:13   #10  |  Link
spoRv
Registered User
 
Join Date: Nov 2016
Posts: 114
Updated post #6 to use Shuffle2D
spoRv is offline   Reply With Quote
Reply

Tags
descramble, scramble

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:49.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.