<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4066027897161735611</id><updated>2012-02-16T11:31:41.562+01:00</updated><title type='text'>maqibooy.com</title><subtitle type='html'>a blog about coding &amp;amp; gaming</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.maqibooy.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default'/><link rel='alternate' type='text/html' href='http://www.maqibooy.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>maqibooy</name><uri>http://www.blogger.com/profile/08853154464511142171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4066027897161735611.post-4042948461829479125</id><published>2011-07-18T20:09:00.004+02:00</published><updated>2011-07-18T20:55:00.114+02:00</updated><title type='text'>Grorld - a CivWorld bonus resource grinding application</title><content type='html'>I really like CivWorld and here is &lt;a href="http://www.maqibooy.com/2011/07/civworld-rambling.html"&gt;my proof&lt;/a&gt;!&lt;br /&gt;&lt;br /&gt;The CivWorld gameplay has one really amusing/annoying feature, the &lt;a href="http://wiki.2kgames.com/civworld/index.php/City#Bonus_Resource_Bubbles"&gt;bonus resource bubbles&lt;/a&gt;. If you hover the mouse over one of these bubbles you will get some extra resources as a bonus. If found that those extra bonuses can be really helpful, at least during the early eras! And you can also win on of the &lt;a href="http://wiki.2kgames.com/civworld/index.php/Contests"&gt;contests&lt;/a&gt; by &lt;a href="http://en.wikipedia.org/wiki/Grinding_%28video_gaming%29"&gt;grabbing those&lt;/a&gt;. I believe most player find those annoying, but I really like these bonuses as a way to thank dedicated players!&lt;br /&gt;&lt;br /&gt;I really need this extra edge that the bonus can supply! I might be the god of all CivWorld players, but my friends ain't. Thats why I ain't winning, right? So I cheat – I'm developed Grorld.&lt;br /&gt;&lt;br /&gt;&lt;a href="https://github.com/maq777/Grorld"&gt;Grorld&lt;/a&gt; is a software that automatically finds bonus bubbles and hover the mouse over those, even while your at sleep.&lt;br /&gt;&lt;br /&gt;This is a blog about coding (and gaming), so I'm going to tell you how I created it! Enjoy the lesson!&lt;br /&gt;&lt;br /&gt;Warning:&lt;br /&gt;This application only works on recent linux system (like &lt;a href="http://www.ubuntu.com/download"&gt;Ubuntu&lt;/a&gt; 11.4). Windows user can preferable stop reading right now, because there will never ever be a port (or maybe a bribe could change me...)!&lt;br /&gt;&lt;br /&gt;I realized that I needed three component to achieve my goal to automatically grind the bonus resources.&lt;br /&gt;1) A screen scraper/reader/grabber to be able to 'see' the game board inside my application.&lt;br /&gt;2) A 'tool' to identify bonus bubbles on the game board.&lt;br /&gt;3) A mouse simulating component to automatically perform the hovering.&lt;br /&gt;&lt;br /&gt;The mouse moving was the simplest, so let's start with that one. The &lt;a href="http://en.wikipedia.org/wiki/Xlib"&gt;Xlib library&lt;/a&gt; supplies a protocol to communicate with the X server. It really helped me with ALL the dirty work. For example: The Xlib API have the &lt;a href="http://tronche.com/gui/x/xlib/input/XWarpPointer.html"&gt;XWarpPointer()&lt;/a&gt; function to move the mouse pointer a distance relative current pointer position. However, as I need to set the mouse position to an absolute point I to retrieve the current position, via &lt;a href="http://tronche.com/gui/x/xlib/window-information/XQueryPointer.html"&gt;XQueryPointer()&lt;/a&gt; , calculated the deltas and set those with XWarpPointer().&lt;br /&gt;&lt;br /&gt;Fully working C code:&lt;br /&gt;&lt;iframe src="http://pastebin.com/embed_iframe.php?i=YnJaTXY7" style="height:400px;border:none;width:100%"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;The screen grabber component was almost as simple. But as the Xlib function &lt;a href="http://tronche.com/gui/x/xlib/graphics/XGetImage.html"&gt;XGetScreen()&lt;/a&gt; is way to slow I had to go and look for alternatives. Fortunately the &lt;a href="http://en.wikipedia.org/wiki/MIT-SHM"&gt;MIT-SHM extension&lt;/a&gt; allows both client (my app) and the server (X) to share memory. Hence you can skip all huge image buffer copying that &lt;a href="http://tronche.com/gui/x/xlib/graphics/XGetImage.html"&gt;XGetScreen()&lt;/a&gt; is using. This &lt;a href="http://personales.mundivia.es/jap/xshm.htm"&gt;XShmGetScreen() tutorial&lt;/a&gt; saved my day.&lt;br /&gt;&lt;br /&gt;The tool to identify bonus bubble is the most interesting. I decided to use a so called &lt;a href="http://en.wikipedia.org/wiki/Template_matching"&gt;template matching&lt;/a&gt; technique. I've used the &lt;a href="http://opencv.willowgarage.com/wiki/"&gt;OpenCV&lt;/a&gt; library before and I like it. Quickly I converted the Xlib pixmap into a OpenCV &lt;a href="http://opencv.willowgarage.com/documentation/cpp/basic_structures.html"&gt;cv::Mat&lt;/a&gt; structure. This image was used as the so called search image. Then I loaded a home made image looking like the bonus bubbles as the so called template image. Thereafter I justed performed a &lt;a href="http://opencv.willowgarage.com/documentation/cpp/object_detection.html#cv-matchtemplate"&gt;cv::matchTemplate()&lt;/a&gt; on the search image. The result is a vector with scores. The item in the vector with the lowest score represent the pixel on the search image that has the highest probability to contain the template image, it can be retrieved with &lt;a href="http://opencv.willowgarage.com/documentation/cpp/core_operations_on_arrays.html#minMaxLoc"&gt;cv::minMaxLoc()&lt;/a&gt;. Afterwards I calculated a relative score with help of &lt;a href="http://en.wikipedia.org/wiki/Standard_deviation"&gt;standard deviation&lt;/a&gt;. Fortunately the OpenCV library have helper function for that as well, &lt;a href="http://opencv.willowgarage.com/documentation/cpp/core_operations_on_arrays.html#meanStdDev"&gt;cv::meanStdDev()&lt;/a&gt;. If the score is 3 sigma or above, we have a 99.7% probability that we have a correct hit. And in that case, I simply hover the mouse over that area...&lt;br /&gt;&lt;br /&gt;Problem solved! And thanks for all the fish!&lt;br /&gt;&lt;br /&gt;Please go and &lt;a href="https://github.com/maq777/Grorld/archives/master"&gt;download&lt;/a&gt; it and tell me how it's working...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4066027897161735611-4042948461829479125?l=www.maqibooy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.maqibooy.com/feeds/4042948461829479125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.maqibooy.com/2011/07/grorld-civworld-bonus-resource-grinding.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/4042948461829479125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/4042948461829479125'/><link rel='alternate' type='text/html' href='http://www.maqibooy.com/2011/07/grorld-civworld-bonus-resource-grinding.html' title='Grorld - a CivWorld bonus resource grinding application'/><author><name>maqibooy</name><uri>http://www.blogger.com/profile/08853154464511142171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4066027897161735611.post-3058850693959740162</id><published>2011-07-14T01:45:00.003+02:00</published><updated>2011-07-14T01:54:59.724+02:00</updated><title type='text'>CivWorld rambling</title><content type='html'>I started to play the &lt;a href="http://apps.facebook.com/civworld/"&gt;CivWorld beta&lt;/a&gt; on facebook the other day. I'm already enjoying it &lt;a href="http://www.civanon.org/"&gt;way to much&lt;/a&gt;! But first we have to go back to when it all begun.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Sid_Meier"&gt;Sid Meier&lt;/a&gt; has been a favorite of mine since long. I played &lt;a href="http://en.wikipedia.org/wiki/Civilization_%28video_game%29"&gt;Civilization&lt;/a&gt; for hours with my friends. We used to go home and play the game together, ain't several minds better than one? This co-operative way of playing a single player game really hooked me. Since that time I been admiring all Sid's work. I've had my ups (CivII, CivRev) and downs (CivIV) due to natural periods in life. Like spending to much time making my own games or producing small children. But I been faithful and played them all.&lt;br /&gt;&lt;br /&gt;CivWorld is the latest installment. It's a so called facebook game. It's still in beta, but I'm already impressed! It has a few flaws, mostly due to the flashplayer that are required! The framerate sucks on my system and the game might not be the deepest in the series. But overall &lt;span style="font-weight: bold;"&gt;the game is brilliant, because the game requires you to team up with friend/other players&lt;/span&gt; to win. It's like a big co-operative Civilization &lt;a href="http://en.wikipedia.org/wiki/Massively_multiplayer_online_game"&gt;MMO&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Did I mention that it's brilliant? It really is! This &lt;a href="http://en.wikipedia.org/wiki/Cooperation"&gt;co-operation&lt;/a&gt; really reminds me of how I played Civilization with my friends back in the days... we now sit in our own houses by ourselfs but we're &lt;a href="http://en.wikipedia.org/wiki/Vulcan_%28Star_Trek%29#Mind_melds"&gt;melting our brains&lt;/a&gt; just like we did in the good old days.&lt;br /&gt;&lt;br /&gt;Plus:&lt;br /&gt;- Gameplay&lt;br /&gt;- Co-operation&lt;br /&gt;- I've almost won my first game&lt;br /&gt;&lt;br /&gt;Minus:&lt;br /&gt;- Flashplayer is required! (HTML5 anyone?)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4066027897161735611-3058850693959740162?l=www.maqibooy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.maqibooy.com/feeds/3058850693959740162/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.maqibooy.com/2011/07/civworld-rambling.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/3058850693959740162'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/3058850693959740162'/><link rel='alternate' type='text/html' href='http://www.maqibooy.com/2011/07/civworld-rambling.html' title='CivWorld rambling'/><author><name>maqibooy</name><uri>http://www.blogger.com/profile/08853154464511142171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4066027897161735611.post-1000517519226083752</id><published>2011-05-29T22:42:00.001+02:00</published><updated>2011-05-29T22:47:39.957+02:00</updated><title type='text'>Du får all min kärlek #9</title><content type='html'>&lt;style type="text/css"&gt; &lt;!--  @page { margin: 0.79in }  P { margin-bottom: 0.08in } --&gt; &lt;/style&gt;&lt;br /&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Spenderade dagen påfotbollscup med dottern och resterande del av familjen. Vädret varganska hyfsat, sol till och från. Men denna historia handlaregentligen inte om fotboll. För tycker du som jag att damfotboll är rätt trist? Du vet, forwards som inte ens med all kraft orkar lyftabollen över ribban eller målvakter som inte ens når ända upp tillribban när de hoppar. Ja, då är det en pina att se 7-8 årigaflickor ge sig an det ädla spelet.&lt;/div&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Men idag, I tredjematchens halvlek, hände något intressant! Den nu snart 5-årigelillebrodern fick sitta med i en liten ring bestående av några'hemma'-spelare. För första gången någonsin kunde ungen sittatyst och stilla mer än 3 minuter! Det hade hänt något, vid dentidpunkten förstod jag dock inte riktigt vad. Men mysteriet skullekomma att klarna.&lt;/div&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Andra halvlek började.Lillebror, som är ganska hetlevrad, skriker svordomar och könsordvid första målchansen och allt känns som vanligt igen. Vid andramålchansen utspelar sig följande konversation;&lt;/div&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Gör mål då nummer nio, skriker lillgrabben.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Skjut, skriker jag.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Gör mål då nummer nio, skriker lillgrabben.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Skjut, skriker jag.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Gör mål då nummer nio, skriker lillgrabben återigen.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Vem är nummer nio, är hon ens på plan?, frågar min sambo och modern till barnen.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Jag scannar av hela planenefter den beryktade spelaren. Jag finner henne bland de andraavbytarna, sittande i en ring. Platsen jämte henne var tom!Målchansen klingar av, föräldrarna suckar och blir tysta. Då,helt till de andra föräldrarnas stora nöje, ställer sig min sonpå den medhavda gröna stolen och skriker högt;&lt;/div&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Gör mål då nummer nio, DU FÅR ALL MIN KÄRLEK #9!&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div lang="sv-SE" style="margin-bottom: 0in;"&gt;Så gick det alltså tillnär grabben gick och kärade ner sig första gången! Jag hoppas dethänder fler gånger, eftersom #9 var bortglömd redan vidkvällsmaten.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4066027897161735611-1000517519226083752?l=www.maqibooy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.maqibooy.com/feeds/1000517519226083752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.maqibooy.com/2011/05/du-far-all-min-karlek-9.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/1000517519226083752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/1000517519226083752'/><link rel='alternate' type='text/html' href='http://www.maqibooy.com/2011/05/du-far-all-min-karlek-9.html' title='Du får all min kärlek #9'/><author><name>maqibooy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4066027897161735611.post-3138557468924391752</id><published>2011-02-13T01:51:00.001+01:00</published><updated>2011-02-13T01:57:02.217+01:00</updated><title type='text'>Lost Odyssey - please think twice...</title><content type='html'>&lt;style type="text/css"&gt;p { margin-bottom: 0.08in; }&lt;/style&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;span style="font-style: normal;"&gt;Thisblog entry is &lt;/span&gt;&lt;span style="font-style: normal;"&gt;dedicated &lt;/span&gt;&lt;span style="font-style: normal;"&gt;onegame, a Japanese game to be specific. I've always loved &lt;a href="http://en.wikipedia.org/wiki/JRPG"&gt;JRPG&lt;/a&gt;&lt;/span&gt;&lt;span style="font-style: normal;"&gt;&lt;a href="http://en.wikipedia.org/wiki/JRPG"&gt;'s&lt;/a&gt;&lt;/span&gt;&lt;span style="font-style: normal;"&gt;, so when &lt;a href="http://en.wikipedia.org/wiki/Lost_Odyssey"&gt;LostOdyssey&lt;/a&gt; was announced I was thrilled. As a Xbox gamer Inever had any chance to play the legendary &lt;a href="http://retro.ign.com/articles/998/998839p1.html"&gt;FF&lt;/a&gt; games (darnyou Sony)... But here it was, a &lt;a href="http://en.wikipedia.org/wiki/Mistwalker"&gt;Mistwalker&lt;/a&gt;developed game for the Xbox 360!&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;span style="font-style: normal;"&gt;&lt;img border="0" src="http://img14.imageshack.us/img14/6760/lostodyssey.jpg" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;b&gt;Is it good?&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Yaah, it's OK. It's not like it's &lt;a href="http://www.urbandictionary.com/define.php?term=over%209000"&gt;over9000&lt;/a&gt; or anything, but its quite entertaining.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Now I probably got you to think twice.Why the hell do I write a complete blog entry about a descent game?It's because NO ONE at Mistwalker did what you just did: THINK!&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;img border="0" src="http://img602.imageshack.us/img602/5894/lostodyssey1.png" /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;b&gt;Me mad!&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;You play as the &lt;a href="http://dictionary.reference.com/browse/immortal"&gt;immortal&lt;/a&gt;hero Kaim who have forgot his past. The main objective game is todefeat the magical industrial revolution.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;While playing the game you experiencevisions/dreams from the past. And I really mean from the past. Youran immortal, you have lived thousand (1.000) years. I promise you, ifyou live a thousand years, you have experienced things really worthdreaming about!&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;I played this game for a week... untilI suddenly dropped the game. I didn't touch the game for 9 months tocome. Even &lt;a href="http://en.wikipedia.org/wiki/Minesweeper_%28computer_game%29"&gt;minesweeper&lt;/a&gt;felt fresh in comparison to the feeling I got from this game.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Here's what happened:&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;img border="0" src="http://img824.imageshack.us/img824/3280/lostodyssey2.png" /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;b&gt;I'm supposed to be IMMORTAL. WTF amI doing dead on the floor?!?! &lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Okay, I finally swallowed my pride andfinished the game. But I have never forgiven Mistwalker for the notso enjoyable experience of becoming a dead immortal!!!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4066027897161735611-3138557468924391752?l=www.maqibooy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.maqibooy.com/feeds/3138557468924391752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.maqibooy.com/2011/02/lost-odyssey-please-think-twice.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/3138557468924391752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/3138557468924391752'/><link rel='alternate' type='text/html' href='http://www.maqibooy.com/2011/02/lost-odyssey-please-think-twice.html' title='Lost Odyssey - please think twice...'/><author><name>maqibooy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4066027897161735611.post-7156636405933706183</id><published>2011-02-09T21:06:00.000+01:00</published><updated>2011-02-09T21:06:49.779+01:00</updated><title type='text'>XOR(42) cipher</title><content type='html'>&lt;style type="text/css"&gt;pre.cjk { font-family: "DejaVu Sans",monospace; }p { margin-bottom: 0.08in; }code.cjk { font-family: "DejaVu Sans",monospace; }&lt;/style&gt;  &lt;div style="margin-bottom: 0in;"&gt;I'm currently reading the book &lt;a href="http://www.amazon.com/Cryptanalytic-Attacks-RSA-Song-Yan/dp/0387487417"&gt;Cryptanalytic Attacks on RSA by Song Y. Yan&lt;/a&gt; for a project I'm currently working on. However, I have to admit, I'm having a hard time with some of the math in that book. For me, this isn't trivial... but at least I'm having a really good time potter with &lt;a href="http://primes.utm.edu/notes/conjectures/"&gt;prime conjecture's&lt;/a&gt;, &lt;a href="http://primes.utm.edu/mersenne/"&gt;Mersenne primes&lt;/a&gt; etc.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;While reading this book my mind wandered off and I started to think about how we did it back in the days. I shared my first computer with my older brother. Hence I had to protect my private data. My private data mostly contained gif pictures of women in bathing suits. Illegally downloaded from &lt;a href="http://en.wikipedia.org/wiki/Bulletin_board_system"&gt;bulletin boards&lt;/a&gt; in countries far far away, but that is another story...&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;a href="" name="btAsinTitle"&gt;&lt;/a&gt;After reading the &lt;a href="http://www.amazon.com/Peter-Norton-Programmers-Guide-IBM/dp/0914845462/"&gt;Peter Norton's Assembly Language Book for the IBM PC&lt;/a&gt; I was ready. I started to encrypt my files with the famous &lt;a href="http://en.wikipedia.org/wiki/XOR_cipher"&gt;XOR42 algorithm&lt;/a&gt;.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;b&gt;The basic idea behind the algorithm:&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Like trivial letter ciphers, the &lt;a href="http://en.wikipedia.org/wiki/ROT13"&gt;ROT13&lt;/a&gt; for example, the idea is that you encrypt &amp;amp; decrypt with the same algorithm. In ROT13 you replace the letter 'A' with the letter 13 places later, the 'N'. And now to the magic! If you once again replace the letter 'N' with a letter 13 places later (using wrap-around) you will '&lt;a href="http://en.wikipedia.org/wiki/Inverse_function"&gt;magically&lt;/a&gt;' get the 'A' letter. You successfully decrypted the data, by encrypting it again.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;On binary blobs, like my images, you instead use the &lt;a href="http://en.wikipedia.org/wiki/Exclusive_or"&gt;&lt;span style="font-weight: normal;"&gt;exclusive disjunction&lt;/span&gt;&lt;span style="font-weight: normal;"&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-weight: normal;"&gt; &lt;/span&gt;&lt;b&gt;(&lt;/b&gt;XOR). It actually has the same effect on each bit, that ROT13 has on each letter.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Encryption;&lt;/div&gt;&lt;pre class="western"&gt;&lt;code class="western"&gt;A B --- A XOR B&lt;/code&gt;&lt;br /&gt;&lt;code class="western"&gt;0 0 ----- 0&lt;/code&gt;&lt;br /&gt;&lt;code class="western"&gt;0 1 ----- 1&lt;/code&gt;&lt;br /&gt;&lt;code class="western"&gt;1 0 ----- 1&lt;/code&gt;&lt;br /&gt;&lt;code class="western"&gt;1 1 ----- 0&lt;/code&gt;&lt;/pre&gt;&lt;div style="margin-bottom: 0in;"&gt; A is my data and B is my key. If I once again use the key B on the now encrypted data, &lt;a href="http://www.yourdictionary.com/ta-da"&gt;ta-da&lt;/a&gt;, each bit will have it's original value again.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Decryption;&lt;/div&gt;&lt;pre class="western"&gt;&lt;code class="western"&gt;A&lt;/code&gt;&lt;code class="western"&gt; B --- A XOR B&lt;/code&gt;&lt;br /&gt;&lt;code class="western"&gt;0 0 ----- 0&lt;/code&gt;&lt;br /&gt;&lt;code class="western"&gt;1&lt;/code&gt;&lt;code class="western"&gt; 1 ----- &lt;/code&gt;&lt;code class="western"&gt;0&lt;/code&gt;&lt;br /&gt;&lt;code class="western"&gt;1 0 ----- &lt;/code&gt;&lt;code class="western"&gt;1&lt;/code&gt;&lt;br /&gt;&lt;code class="western"&gt;0&lt;/code&gt;&lt;code class="western"&gt; 1 ----- &lt;/code&gt;&lt;code class="western"&gt;1&lt;/code&gt;&lt;/pre&gt;&lt;div style="margin-bottom: 0in;"&gt; This is best performed on complete bytes (8bits). And the most commonly used key is of-course 00101010b (&lt;a href="http://en.wikipedia.org/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy_%28novel%29"&gt;42&lt;/a&gt;).&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;The letter 'A' is represented as the number 01000001b (65) in the &lt;a href="http://www.asciitable.com/"&gt;ASCII table&lt;/a&gt;.&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Encryption;&lt;/div&gt;&lt;pre class="western"&gt;&lt;code class="western"&gt;01000001b XOR 00101010b = 01101011b (encrypted to ASCII character 'j')&lt;/code&gt;&lt;/pre&gt;&lt;div style="margin-bottom: 0in;"&gt; &lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;Decryption;&lt;/div&gt;&lt;pre class="western"&gt;&lt;code class="western"&gt;01101011b XOR 00101010b = 01000001b (decrypted back to ASCII character 'A')&lt;/code&gt;&lt;/pre&gt;&lt;div style="margin-bottom: 0in;"&gt; &lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;b&gt;Code examples:&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;It is trivial to implement such algorithm in C-code, this is one example how this task can be achieved:&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;iframe src="http://pastebin.com/embed_iframe.php?i=4uFjQ7qd" style="border: medium none; width: 100%;"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;It may originally be consider as a joke but the GNU C library authors gave us &lt;a href="http://www.gnu.org/s/libc/manual/html_node/Trivial-Encryption.html"&gt;memfrob&lt;/a&gt;. The library function XOR bytes in a very efficient manner (they actually call it frobnicates). Simple usage would look like;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;iframe src="http://pastebin.com/embed_iframe.php?i=fThWsM1M" style="border: medium none; width: 100%;"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;XOR42 should not be consider to be a real encryption. There exists reasons why everyone, including me, is using &lt;a href="http://openssl.org/"&gt;openssl&lt;/a&gt; for encoding. However, I believe the following modern encryption example is way to simple and boring;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;iframe src="http://pastebin.com/embed_iframe.php?i=qbjbihdF" style="border: medium none; width: 100%;"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;And NO, my brother never succeeded to decipher any of my private data...&lt;/div&gt;&lt;div style="margin-bottom: 0in;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4066027897161735611-7156636405933706183?l=www.maqibooy.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.maqibooy.com/feeds/7156636405933706183/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.maqibooy.com/2011/02/xor42-cipher.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/7156636405933706183'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4066027897161735611/posts/default/7156636405933706183'/><link rel='alternate' type='text/html' href='http://www.maqibooy.com/2011/02/xor42-cipher.html' title='XOR(42) cipher'/><author><name>maqibooy</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
