Skip to content

Silveira Neto Posts

Visual Cryptography

Visual_crypto_animation_demo

Two basic articles on visual cryptography:

One interesting thing about this schema is that can be applied for stenography and can be simply implemented physically using only shadows.

Update: a shorter explanation with examples.

See too: One Time Pad Using Gimp.

ImageMagick, four point perspective distortion in a video

Step 1) Download the video from Youtube using JDownloader. The best one was the original Japanese upload, The Game Awards 2014 出展映像 ゼルダの伝説 最新作, which is 720p. I saved this file as zelda_720p.mp4.

Step 2) Transform the video in a series of PNGs.

[bash]mplayer -nosound -vo png:z=9 zelda_720p.mp4[/bash]

This generated image files ranging from 00000001.png to 00007563.png.

Step 3)
Using Gimp, find the 2 sets of 4 points for the perspective. The first in red is the source and the one in blue is the destination.

zelda video four point perspective

Step 4) Apply ImageMagick’s four point perspective distortion in each image using a ShellScript.

[bash]
#!/bin/sh
for image in *.png;
do
convert $image -matte -virtual-pixel transparent \
-distort Perspective \
‘60,90 0,0 50,415 0,720 582,418 1280,720 589,147 1280,0’ \
p_$image
done
[/bash]

Now I have images in the format p_00000001.png to p_00007563.png. Because PNG is a lossless format, the perspective lost less information in this step than it would if step 2 was outputting jpgs.

Step 5) Convert frames to jpgs using ImageMagick and ShellScript.

[bash]
#!/bin/sh
for image in p_*.png;
do
convert $image "${image/.png/}.jpg"
done
[/bash]

Where “${image/.png/}.jpg” removes the .png in the image string.

Ps: this step is not really necessary as you could use png as input to ffmpeg.

Step 6) Convert jpgs in a video.

[bash]
ffmpeg -start_number 0 -i ‘%08d.jpg’ -c:v libx264 output.mp4
[/bash]

‘%08d.jpg’ means a 8 digits filled with zeros in the left followed by .jpg, in this case 00000001.jpg to 00007563.jpg.

With this, I have the output.mp4 video ready to upload.

The whole process took several hours and a total 13GiB, although the final video has only 96 MiB. This could be optimized using pipelines and parallelism if it was needed to repeat the process.

HackerNews discussion: https://news.ycombinator.com/item?id=8713070

Telephone keypad combinations

Problem: Given a sequence of numbers, show all possible letter combinations in a telephone keypad.

Recursive solution in Python:
[python]
keyboard = {
‘1’: [],
‘2’: [‘a’,’b’,’c’],
‘3’: [‘d’,’e’,’f’],
‘4’: [‘g’,’h’,’i’],
‘5’: [‘j’,’k’,’l’],
‘6’: [‘m’,’n’,’o’],
‘7’: [‘p’,’q’,’r’,’s’],
‘8’: [‘t’,’u’,’v’],
‘9’: [‘w’,’x’,’y’,’z’],
‘0’: []
}

def printkeys(numbers, prefix=""):
if len(numbers)==0:
print prefix
return

for letter in keyboard[numbers[0]]:
printkeys(numbers[1:], prefix+letter)

printkeys("234")
[/python]

Output:

adg
adh
adi
aeg
aeh
aei
afg
afh
afi
bdg
bdh
bdi
beg
beh
bei
bfg
bfh
bfi
cdg
cdh
cdi
ceg
ceh
cei
cfg
cfh
cfi

permutations implemented in Python

In case you can’t use Python’s itertools or in case you want a simple, recursive python implementation for a permutation of a list:

[python]
def perm(a,k=0):
if(k==len(a)):
print a
else:
for i in xrange(k,len(a)):
a[k],a[i] = a[i],a[k]
perm(a, k+1)
a[k],a[i] = a[i],a[k]

perm([1,2,3])
[/python]

Output:

[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 2, 1]
[3, 1, 2]

This Python implementation is based in the algorithm presented in the book Computer Algorithms by Horowitz, Sahni and Rajasekaran.

endless tail in a file

tail -n 50 -f your.log
  • –folow or -f FILE to output appended data as the file grows
  • –lines or -n K output the last K lines of the file

Alternatively,  you can also use watch.

Spring

suyane drinking tee looking through the window

Stereo photo taken using a Nintendo 3DS XL. As browsers don’t support MPO files yet, I had to split the file into two JPGEs, then manually align and convert to animated gif using GIMP.

A poesia está guardada nas palavras

“A poesia está guardada nas palavras – é tudo que eu sei.
Meu fado é o de não saber quase tudo.
Sobre o nada eu tenho profundidades.
Não tenho conexões com a realidade.
Poderoso para mim não é aquele que descobre ouro.
Para mim poderoso é aquele que descobre as insignificâncias (do mundo e as nossas).
Por essa pequena sentença me elogiaram de imbecil.
Fiquei emocionado e chorei.
Sou fraco para elogios.”

Tratado geral das grandezas do ínfimo, Manoel de Barros

“The obsolescence of an implementation must be measured against other existing implementations, not against unrealized concepts.” The Mythical Man-month – Essays on Software Engineering. Freederick P. Brooks, Jr.

Bash Brace Expansion

photo by whiskeyandtears at https://www.flickr.com/photos/whiskeyandtears/2140154564

[bash]$ echo {0..9}
0 1 2 3 4 5 6 7 8 9[/bash]

[bash]$ echo b{a,e,i,o,u}
ba be bi bo bu
[/bash]

[bash]$ echo x{0..9}y
x0y x1y x2y x3y x4y x5y x6y x7y x8y x9y[/bash]

[bash]$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z[/bash]

[bash]$ echo {1..3} {A..C}
1 2 3 A B C[/bash]

[bash]$ echo {1..3}{A..C}
1A 1B 1C 2A 2B 2C 3A 3B 3C[/bash]

[bash]echo {a,b{1,2,3},c}
a b1 b2 b3 c[/bash]

[bash]$ mkdir -p {project1,project2}/{src,tst,bin,lib}/
$ find .
.
./project1
./project1/tst
./project1/bin
./project1/lib
./project1/src
./project2
./project2/tst
./project2/bin
./project2/lib
./project2/src
[/bash]

[bash]$ echo {{A..Z},{a..z}}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z[/bash]

[bash]$ for i in {a..f} 1 2 {3..5} ; do echo $i;done
a
b
c
d
e
f
1
2
3
4
5[/bash]

The examples below requires Bash version 4.0 or greater.

[bash]$echo {001..9}
001 002 003 004 005 006 007 008 009
[/bash]

[bash]$ echo {1..10..2}
1 3 5 7 9
[/bash]