A tribute to “pretty good privacy” or PGP …


I found a breakdown of the design of this security algorithm still in use a quarter-century after its creation; but the designer obviously never took a course in design docs or spec; so here is my re-made rendition. (processes/functions/methods are rectangular, [most] data is parallelogram-ular (??)…all other symbols, descriptions, connections, emoji’s and hyperlinks should be intuitive. Created by Bill Feynman at self-sim-sususudios 11/16. the following is a link to the odf if you’d like to download and improve/edit/whatever….pgp-diagram pgp-diagram
for JP, find him @www.analogdesign.com

The least common multiple of three integers; a solution in Java ….

This was inituially a troubling proposition because I’d mixed up “least common multiple” with greatest common factor. Further, the question posed to solve the LCM of three prime integers, namely; three, five and seven. I answered the question as “duh…one.” and moved on. Thx to fellow wikireviewer Eric Barnes who noted the error. I looked up the euclidean definition of what LCM really means…then coded two functions and tested them in a main class. The code is adequately introduced, commented and documented to explain the algorithm’s process, which is essetailly to calculate the LCM of 5 & 7, then save that 1st lcm and plug it into a separate function that will calulate the final LCM using 3 and “lcm of 5 & 7” as parameters.

/**we define the lcm of three ints as follows:
* LCM(a,b,c)=LCM(LCM(a,b),c)=LCM(a,LCM(b,c))
* the lcm of 3, 5 & 7 is, in fact 105
* last stable build 1/24/16 @ssstudios, los angeles, ca
* IP! &c Tapper7.com, ssstudios and lonely faction productions*/
package gcd;
public class Gcd{
public static int gcd(int a,int b){
int t;
while(b!=0){
t = b;
b = a%b;
a = t;
}
return a;
}//end fxn gcd
public static int lcm(int x, int y){
return(x*y/gcd(x,y));
}//end fxn lcm
public static void main(String[] args){
int lcm1 = 0; //will store the lcm of parameter 2 & 3
int lcm2 = 0; //will store the result of lcm(p1, lcm(p2,p3))
int p1 = 3;
int p2 = 5;
int p3 = 7;
lcm1 = lcm(p2,p3);
lcm2 = lcm(lcm1, p1);
System.out.println("The least common multiple of " +p1+ ", " + p2 + ", "
+p3+ " is " +lcm2);
}//end mn
}//end gcd/lcm class tester

here is the result:

run:
The least common multiple of 3, 5, 7 is 105
BUILD SUCCESSFUL (total time: 0 seconds)

therefore, Barnes is correct. Thank you for pointing out my foible and giving a chance to review & test this classic algorithm. I just set up an entirely new IDE on an entirely new system so this made for great QC on the new devkit & system too.

A Die Class that implements Crap…I mean ‘Craps’ in Java ….

I took a step back from cards and decks to see if I could design and build a crap game using some object-oriented design. To play the game, we roll two die. The result is determined by the sum of the two rolls….a number between two and 12. Put simply, seven and 11 means the roller “won,” any other result is some form of push or loss…”snake eyes [2]” and “box cars[12]” usually equate to a bust. We can make up specific rules when we implement the game itself, or change them on the fly. The key concept here the abstract data type I built – Class Die.

Lets think about what a die IS and what it DOES. In computer science terms, we’re going to build a virtual die based on my observation/interpretation of these aspects of this object. For a game of craps, I’m concerned with the die’s current status, that is, what is face up on this hypothetical die right now? What is face up if I create a new one out of thin air? What is face up after I roll it? Compared to a Card, a Die object is relatively simple. While a card has a suit and rank, a die only has a face value. The important thing to consider is that when we roll it, one, two, three, four, five and six should occur with a relatively even distribution – as close to random as we can get. How we determine a random number in this range, how we determine that a computer-generated number is “random” at all is beyond the scope of this discussion; for now …assume that the Java Virtual Machine can in fact do this. We can create another program later to test it, say… a million times and see how evenly the JVM can emulate randomness.

Here are the “body parts” of the Die I created – “face up” I used an integer and called it “state”…to create a new Die I initialized it to have one be face up. Since I need to read the face, I created a “print state” method. Of course, a “roll” method was created — which will change the state (or not! 1/6th of the time….) I also buiis lt a function that will immediately return the current state (to whatever interface needs to use it) as an integer; this is fast and useful once an actual game using dice is built – common coding standards would ask that we call this a “get[State]”
There are probably a few other things a die has and does, in fact, we should have an ability to put the “state” where we want it; a “set” procedure…in terms of the game; this would presumably be some sort of cheating, so we left it out. For now…anyway here is the abstract data type:

package die;
import java.lang.Math;
import java.util.*;
//this is a WIP!!
public class Die{
int state;
public Die(){
state = 1;
}
public void printstate(){
System.out.println(state + " is face up");
}
public int roll(){
int a;
Random roll = new Random();
a = 1+Math.abs(roll.nextInt()%6);
state = a;
return a;
}
public int getstate(){
return state;
}
}//end Die

The way I built this, a main program will have to create two instances of “Die,” roll them, determine a sum and evaluate/output the result. The class above neatly and concisely provides everything we need to play the game. In the code we will create dice using a statement like this- “Die the1st = new Die();” Let’s take a look at what happens when this line is executed.
the = or assignment operator will move from right to left…so the 1st thing that happens is the cpu allocates memory for it (which shouldn’t cost much more than the memory needed to store one integer 16…perhaps 32 bits (???)…the “new” keyword also pulls the constructor method seen above, which will initialize it to have “one” be “face up” …in the class above — Die(){state=1;}

Then we will create a second die, everything I just said will happen again. In the game, we’re gonna roll ’em and figure out what happens. As we build the main class, we will use printState() and getState() frequently to verify that our dice are behaving like we would expect real dice to. Remember, we are creating them in a strictly abstract sense, we can’t hold them, look at them or actually roll them…so we need to poke and prod at these dice as the game goes … debugging the code if anything out-of-the-ordinary happens.

Later we will take a look at the entire source code; for now lets consider some key moments in a single round of craps. The player rolls, he either wins or loses, so we start by calculating the sum.

mydie.roll();
mydie1.roll();
sum = mydie.getstate()+mydie1.getstate();

The above sum tells us what happened. I added a Boolean method to the Die class to determine victory and a branching-if-then-else method to print what happened …

//this is in the main class
currentstack = currentstack - betamt;
if(won(sum)){
System.out.print(" WINNER ");
currentstack*=3;
}
else if(sum==2 || sum == 12){
System.out.print(" OUCH!! ");
currentstack=0;
bust = true;
}
else{System.out.print(" LOSER ");}

Don’t worry too much about the specifics; it should be easy enough to see that, in pseudocode

SUBTRACT the players bank by how much they BET
IF the player WON
MAKE Notification, increase their money
ELSE the player LOST
IF the player rolled SNAKE EYES or BOXCARS
Make Notification, player BUST
IF the player rolled some other value
Make Notification, reduce their money

The rules I used are arbitrary, essentially we want something good to happen if the roll a seven or 11, something bad to happen if not…and something REALLY BAD to happen if they roll a two or 12. As it is set right now, “snake eyes” or “box cars” leads to player bust- in this case they lose everything and the game is over. Winning triples their money, as written and the game continues provided the player has more than $1 to play with. I’ve yet to decide exactly what happens, but really it doesn’t matter. The design allows for any rules regarding what you get if you win, what you don’t get if you lose, how badly you can lose, if/when the player can choose to quit and if/when the cpu will decide to end the game.
the class method “won” is fairly straightforward. TRUE will be sent back if the condition is met.

public static boolean won(int s){
return(s==7||s==11);
}

In the next installment, I will decide on some actual rules, show some sample outputs of the game in progress along with some research to see if the Java Virtual Machine is, in fact, emulating the rolling of two die by writing a special use-case in which we’ll roll each die a million times and see how normalized the randomness really is.

Let’s play…I mean…create a prototype ’13’ deck aka Korean Poker!

If you are like me you played this addictive game at lunch, on the bus, during class…whatever you played it constantly because it’s seriously fun and a great way to pass the time. At Capo Valley, we loved this game because it was winnable even if you were dealt a shitty hand, the game encouraged a great deal of shit-talking and merriment. We’d also enhanced it with “insult rules” such as, while dealing, you throw a few of them face-up, just to piss off whoever you want to piss off. It also lended itself to so much cheating that we overlayed a rule; “If no one saw it, it wasn’t cheating.” Technically that is true in the absolute…the difference is that we encouraged cheating because it added more layers of fun, strategy, dexterity, options to win…the perfect game for college-prep band geeks who think to much and are fiercely competitive.
Common ways to cheat when you re the dealer is place a card you want on the bottom of the deck, dealing, 13 cards to each player beginning with west, you get the final card. Desirable cards include the 3 of clubs (whomever holds this card goes 1st…it is much like other games where whomever runs out 1st wins, going 1st on a good hand could end it). The ace of hearts is valued – any run ending in this card is unbeatable (thus you get to go again). Likewise, the 2 of hearts is valued for being the highest card – it is not unbeatable (a two-killer is a double-run-of-three such as 4,4,5,5,6,6) but it’s always nice to have, especially late in the game when most pairs and runs are likely to be all down. Another great way to cheat it to simply hide a card (or two, or more…) wherever you can hide it. The best place seemed to be under the left thigh or up my right sleeve. Another “layered” rule is that if you are caught cheating you forfeit the game (and winning if gambling is involved) – simply trying to look at other people’s cards is another surprisingly easy way cheat.
I won’t waste time with any more specific rules…most of you have never played it…still, the f-ed up ways to mess with the game applies to all of them (and that only scratches the surface) and you can apply the tenets and ideas in this post to YOUR preferred card game.
On topic – I’ve been brushing up on mu Java programming again so as a thought experiment I began to build a “Card” class (ADT, data-type, etc). Once I got that to work I decided to test it by creating an array (a list) of them and ordering them in the exact order they would go in 13. On higher level of this project are the following:

  1. A Deck Class
  2. A 13 Class
  3. A user-interface for the game itself

For now, I simply used my Card data-type to see if I could use a nested-for loop to populate the deck with cards as they from low to high in the game of 13. Software Engineers know that regardless of language, arrays begin at zero. In an object-oriented mode, I decided that “zero” had so little to do with cards/decks/card-games that I would use a place-holder for it. What else is not used…I mean…in actual card games? For most; the Joker(s), so in the interest of something w/in striking distance of elegant design; (in pseuodocode) 0=(string)”joker”
The following is the output from a Deck prototype, which hints at an actual 13 prototype, which is a thought experiment for the future…particularly the design of three players who can plot against me…and..on an absurd level of abstraction…try to cheat me if the opportunity comes up and allow me to cheat the non-player-characters.

Below is the successful output from the v0 prototype of a 13-Deck
run: whomever gets the 3 of spades goes first.
The following list will create a deck of 52 cards in ’13’ order
1. created the 3 of spades
2. created the 3 of clubs
3. created the 3 of diamonds
4. created the 3 of hearts
5. created the 4 of spades
6. created the 4 of clubs
7. created the 4 of diamonds
8. created the 4 of hearts
9. created the 5 of spades
10. created the 5 of clubs
11. created the 5 of diamonds
12. created the 5 of hearts
13. created the 6 of spades
14. created the 6 of clubs
15. created the 6 of diamonds
16. created the 6 of hearts
17. created the 7 of spades
18. created the 7 of clubs
19. created the 7 of diamonds
20. created the 7 of hearts
21. created the 8 of spades
22. created the 8 of clubs
23. created the 8 of diamonds
24. created the 8 of hearts
25. created the 9 of spades
26. created the 9 of clubs
27. created the 9 of diamonds
28. created the 9 of hearts
29. created the 10 of spades
30. created the 10 of clubs
31. created the 10 of diamonds
32. created the 10 of hearts
33. created the J of spades
34. created the J of clubs
35. created the J of diamonds
36. created the J of hearts
37. created the Q of spades
38. created the Q of clubs
39. created the Q of diamonds
40. created the Q of hearts
41. created the K of spades
42. created the K of clubs
43. created the K of diamonds
44. created the K of hearts
45. created the A of spades
46. created the A of clubs
47. created the A of diamonds
48. created the A of hearts
49. created the 2 of spades
50. created the 2 of clubs
51. created the 2 of diamonds
52. created the 2 of hearts
*QA test* The highest ranking card in 13 is the 2 of hearts
BUILD SUCCESSFUL (total time: 0 seconds)

It works! Created using the Netbeans IDE 8.0.2 on a win8.1 box using the Java SE 8 or Java 1.8 as I call it. SRC follows:

package card;
/** WIP - create a card ADT and enumerate it into a deck  per "13" rules aka Korean Poker @author Tapper7.com last stable build - 12/15 &c ssstudios, los angeles, ca
*/
public class Card{
int suit;
int rank;
Card(){
this.suit = 0;
this.rank = 0;
}//null constr
Card(int suit, int rank){
this.suit = suit;
this.rank = rank;
}
public static void showCard(Card theCard){
//cards are ranked as they are in 13 aka korean poker
//"jokers" hold null memory space so we arent using zeroes
String[] s = {"joker", "spades", "clubs", "diamonds", "hearts"};
String[] r = {"joker", "3", "4", "5", "6", "7", "8",
"9", "10", "J", "Q", "K", "A", "2"};
System.out.println(r[theCard.rank] + " of " + s[theCard.suit]);
}
public static void main(String[] args){
//create an array of cards
Card[] mydeck = new Card[54]; //array is oversized for debug
mydeck[0] = new Card(1,1);       //initialize
//test that the lowest card is created correctly
System.out.print("whomever gets the ");
Card.showCard(mydeck[0]);
System.out.println("goes first.");
//populate the 13 deck in order from low to high
int currentCard = 1;
int suits = 1;
int ranks = 1;
System.out.println("The following list will create a deck of 52 cards in '13' order");
for(ranks = 1; ranks < 14; ranks++){//outerloop ranks from 3,4,5....J,Q,K,A,2
for(suits = 1; suits < 5; suits++){
mydeck[currentCard] = new Card(suits, ranks);
System.out.print(currentCard+". ");
System.out.print(" created the ");
Card.showCard(mydeck[currentCard]);
currentCard++; //increment deck position
}//end inner loop
}//end outer loop
//test that the algorithm put the highest card in the correct index:
System.out.print("*QA test* The highest ranking card in 13 is the ");
Card.showCard(mydeck[52]);
}//end mn
}//end prototype

thanks for stopping by! and now [below], a word form one of our sponsors

From static frames to animation – JavaScript, Java & Processing; coding Art ….

As part of my research, I endeavored to build a frame and tile itevenly…as you would a column in a upscale restaurant, or as Billy-Buster tiled his lesser-known below-ground pool in the hilltop paradise above San Simeon. Drawing squares, keeping track of their quantity, position and spacing proved unweildy. So back to the drawing board I turned. The first task was to completely fill a window with squares, evenly spaced, uniformed – no holes. My first breakthrough was a rectangular grid – from the drawing board I found that instead of looping to keep track of the squares (their origins in CGI coordinates space, their quantity, when to drop down a row, when to stop building them…) oy! I located a KISS-simple solution in the following functions and abstract data types:

Click to see it transform.
Some tweaks to a nested-for loop, appropriate “pops” nee popMatrix(); and the careful application of a “random” number generator to produce cool-colored tiles —but not TOO cool — experiment yielded a random range in Green and Blue to give the tiles a watery sheen, sans magenta, indigo, dark purple and the like. For personal intersest and further research I added a mouse event that slows down the animation, eliminates the thin black borders on each tile and zooms in on the whole operation.
At long last “Random dynamic & cool tiles” is up for public consumption:
I could see a pool in Laguna, LA, Vegas or Laughlin with swanky, swarthy, light-up tiles in a pool or on a wall of it’s club …. Bill R. Hearst would be pleased…I like to think so.
Next – I thought about Neil Degrasse Tyson. He says that the “snow” we see on the “TV channels in-between TV channels,” (something our Millennial friends may never fully appreciate…) is ACTUALLY a visual representation of the background radiation that’s permeated the Universe since the Big Bang. UHF & VHF cathode-ray displays pick up this noise and spit out the “ssshhhhhhhh” and the black, white & gray snow we may’ve found on Channel 1 or 3. Mostly, it was annoying and caused us to quickly dial up to CBS, PBS, NBC, FOX or ABC to see what was cookin’….but in the context of nostalgia, the scientific implication of looking back seven trillion years; this “snow” is worth an emulation. Using similar logic I fashioned version 1. The snow doesn’t dance around the screen, but the small circular “flakes” and the way they appear to move based on random gray-scale shadings is a nice start. It looks like they move – kinda.
^^^^I slowed the frame rate down to avoid headaches.
After random “cool” I had to attempt random “warm” –this graphic reminds me of a HollyWood or Vegas marquee. Bright lights seize attention; underscoring the glitz and glamour purported to be found within. The difference is that I think the bulbs this animation emulates are controlled in strict, looping sequences as opposed to my random flashes of “bright” colors controlled by logic.
This animation reminds me of the “Sushi”scene from “Defending Your Life” — Albert Brooks’ barmate proudly states that his life accomplishment was coining the phrase “All Nude. (You know those strip clubs out by LAX? ….“) You needn’t be a fan of his quirky brand of humor to get huge kick out this classic.
That said, I FINALLY got the computer graphic programs to not only display but animate! The “random- (random number generators are not TRULY random, but they are close)-ness” of the algorithms give the displays a kind of innate ability for the computers to create something of THEIR OWN — MY LOGIC & Design—> the computers’ brushstrokes.
All of the “sketches” (as they call them) on my new OpenProcessing Profile are completely original – designed, built, tested, tweaked and deployed by this writer. If you visit my new page & graphics, the source code is easily visible. Feel free to reproduce it yourself, or make changes/improvements to it. You will find that all of them are optimized –nee “code-golfed.” I designed these algorithms to use the fewest lines of code, fewest commands and simplest logic to add a layer of mathematical elegance to the aesthetic of each sketch. Please feel free to download my source code…just plz note that all of them are intellectual property- if you plan to use them in a public/educational or commercial setting…just ask! chris@tapper7.com
More coming soon….plus a litany of fresh podcasts – “I swear it by the old gods & the new.” -t []

How to remove unwanted footer display and links in WP (and PHP, HTML) ….

This is a rehash of a previous how-to, but now that us WP “developers” have updated to v4.3….some of the unwanted PHP scripts and other junk may have returned to our sites. Let’s fix it fast–right now! In my case I prefer to get rid of the footer materiel that plugs a) the theme OP creator and b) WordPress itself. Why do we ditch PHP scripts that form the backbone of what the audience sees when they go to our-self-aggrandizing-website.com?

  1. Personalization – my site should contain MY approved content, especially links to 3rd parties
  2. Ownership– no one needs to know that my site is “powered by” ANYONE except ME, my associates and (mt)
  3. Control – anything viewed on my site NOT expressly approved by the publisher is unprofessional
  4. Anonymize – no one needs to know (or cares) that The Picayune runs WP or it’s reliance on a PHP template

Let me elaborate on Ownership – this is MY SITE! MINE MINE MINE! Pride is NOT a sin in the creative and technical world, 3rd party link-stingers at the bottom of my pages say, “you may enjoy this site but REAL credit goes to the open-source Web development firms that wrote some code running in the background.”
^^^^ F— them. The publisher built this site from nothing, the publisher
bashes his head in over every post and pixel, the publisher marketed the content and developed a loyal audience….THE PUBLISHER obeys all US Media Law and applicable media ethics…THE PUBLISHER creates original, rich, deep, informative, occasionally funny content… THE PUBLISHER was approved for Google Adsense almost a year ago. NOT WORDPRESS and certainly not a theme developer who’s code only loosely applies to what I still call “The Socal Picayune WP Theme 2015.”….so now that we’ve made updates, let’s try a quick how-to on what I call “WordPress footer anonymization.” Last time we had to re-write the “<>” (HTML & PHP browser directives) to “[]” as the “code” markup in WP 4.1 (or was it 4.0?) would glitch out, the WYSYWIG interpreting the brackets inside as real, despite the fact that the “code” (I’m still weary of using brackets for that word till the following test….) ostensibly tells your browser – “The following characters are all plain text – display them AS WRITTEN” — return to normal HTML when “/code” appears. For HTML beginners, this is the same as a bold command in a word processor. In a markup language a directive tells the browser what to do with incoming strings of text. Here is the simple example:

BOLD
— the rough equivalent of [strong] BOLD [/strong] –or– (b) BOLD (/b) ….again I’m using arbitrary beginning and ending brackets instead of “<” and “>” so as not to confuse the post the site will generate. Essentially in markup symantics, the directive %strong% indicates a change to the input string; the %/strong% (<—note the fwd-slash) indicates it is over. Ok…let’s give this a try… If WP 4.3’s WYSYWIG editor STILL bugs out on the “code” markup, I will post a snapshot this time instead of replacing all the greater-than & less-than symbols with ‘[‘ & ‘]’sTEST! 

  1. Dashboard –> Appearance –> Editor –> open footer.php
  2. Make a local backup copy of “footer.php” in case you screw it up
  3. delete or comment out the code snippet pictured below
  4. Update file (this will recompile the site with updated PHP script)
  5. Visit site – (for QA/QC)

*UPDATE* “code” does not work w/in a WP post – It’s likely that the markup itself is followed by another markup using the less-than ‘<‘ sign – this exception is either not coded into WordPress’ WYSYWIG editor or fails on the front-end of common browsers. I really don’t have the interest to solve this, so here is a snapshot of the code I removed:

//coment_out or delete

Let’s note what I removed in ditching the above:

  • A banner link to WP.com (or .org….)
  • A banner link to another webdev’s site

Let’s note what I DID NOT remove* (you won’t want to either. Directly above the call to a footer class, there is this command – “…do_action(‘generate_after_footer_widgets’);?> This fuction will return widgets embedded at the bottom of the page; MY content, so it stays. In my case, currently there are three footer widgets here– a plug for my fledgling podcast, links to other pages on the site and a calendar.

This test was successful on previous versions of WP v4 and is currently working no problemo on WP v4.3 running on a reliable server courtesy of Media Temple.
If you find the content here informational, entertaining, laughable or get SOME form of enjoyment out of it, you’d be doing us all a great big favor by checking out one of our generous sponsors. As always, there is no need to buy anything…not from me or any site plugged by me ever, but browsing Google Adwords-audited sponsors is of no danger to anyone. A banner ad may or may not appear below – the WP 4.3 testing continues….

Here is a less Object-Oriented example…this Stylesheets’s “original” author, or OP as I called one above, wrote so much unwanted junk AND script-kittied (nee plagiarized) so much of other’s that he mentions it’s “OK not to link to my site in the footer, but credit appreciated.” Sorry…. f— his “credit” take a look at the code:another footer removal example

Ok so as a courtesy you can see some names were changed and the Web site is bogus. Exercise: What PHP and HTML can we safely comment-out or outright delete?  To give you a hint this code will generate the following at the bottom of your page:

BlahBlahhoohooblahh 2015 WordPress Theme by www.someUnwantedBacklink.com Another Boring Theme

(another thing worth noting is that function ‘.date(“Y”)’ in this case will read the date from your computer, extract the year as a 4-digit integer and print it using the style defined for <p> in the stylesheet, I say this because it may not be 2015 when you read this and I don’t want to confuse anybody)

Ok…..ready? Here is a KISS-simple solution to wipe out all that nonsense (or rewrite/replace it with your own…link to an associated page or your client, whatver’s clever, You strip this down to:

</footer> </body> </html>

TaDaaa!

Is any of my content helping? If so…could do me a solid and visit one of my generous sponsors? I could really use the help. You don’t have to buy anything….that is part of The SoCal Picayune, Self-Similarity Studios and Tapper7.com promise: ads are clearly labeled, separated from site content and no financial obligation is ever expected of audience members. That said ….

*A note for beginning front-end developers: If I need to tell you why >? was not deleted, this is perhaps too advanced a tutorial – be careful not to remove /body or /html at the end of the file — again — make a BACKUP before changing HTML/JS/PHP etc. inside your page or it could be kablammo; you won’t destroy the site, but you WILL take it down and need to FTP as an administrator and swap out the PHP file to get your site back up. Unless you have unrestricted access to the backbone of your site … this will lead to a call for tech support from GoDaddy or whomever you use…and who the hell knows how long that will take? Learn as much about PHP, FTP, mySQL, HTML, CSS, JS and common contruction tools like Website Builder, cPanel and WordPress if you are a small operation – it will save you time, $ –and trust me it’s NOT COMPLICATED. These are not programming languages, they are scripts and applications – if you can put together a mean-looking Power-Point; you can do this!).
More posts, stories and podcasts coming soon, -t. []