## Rail-Fence Cipher

### March 31, 2009

The obvious solution uses arithmetic to extract characters at the various positions of the text in the desired order. But the details are tricky and hard to get right. Matthias Felleisen, a Professor in the Computer Science department at Northeastern University in Boston and one of the authors of The Little Schemer proposes instead the following solution:

`(define X '_) ; a unique tag for padding the data structure`

`Waves` splits a text into pieces of length equal to the key; alternate pieces are reversed and have their first and last characters padded. For instance, `(waves (string->list "PROGRAMMING PRAXIS") 4)` evaluates to `((#\P #\R #\O #\G) (_ #\A #\R _) (#\M #\M #\I #\N) (_ #\space #\G _) (#\P #\R #\A #\X) (_ #\S #\I _)).`

``` (define (waves str h)   (define (down str)     (if (>= h (length str))         (list (fill h str))         (cons (take h str) (up (drop h str)))))   (define (up str)     (if (>= (- h 2) (length str))         (list (pad (fill (- h 2) str)))         (cons (pad (take (- h 2) str)) (down (drop (- h 2) str)))))   (define (pad str) (append (list X) (reverse str) (list X)))   (define (fill h str) (append str (make-list (- h (length str)) X)))   (down str)) Fence uses waves to produce a list of the positions from which the transposed characters will be taken. For instance, (fence (range (string-length "PROGRAMMING PRAXIS")) 4) produces the list (0 6 12 1 5 7 11 13 17 2 4 8 10 14 16 3 9 15). Fence uses waves to perform the transposition: (define (fence lox h)   (define a (apply append (transpose (waves lox h))))   (filter (lambda (e) (not (eq? X e))) a)) Encipherment is done by calling fence: (define (encipher str h)   (list->string (fence (string->list str) h))) Decipherment is somewhat more difficult. Fence builds a list of the positions of the transposed characters; for our running example, e will be (0 6 12 1 5 7 11 13 17 2 4 8 10 14 16 3 9 15). Those positions are melded with the cipher-text in x, the position/character pairs are sorted into order in y, and the characters extracted in z: (define (decipher str h)   (define e (fence (range (string-length str)) h))   (define x (map list e (string->list str)))   (define y (sort (lambda (i j) (<= (car i) (car j))) x))   (define z (map cadr y))   (list->string z)) Felleisen's program is simple and clear, a fine example of beautiful code by a master of the craft. Running the rail-fence cipher looks like this: > (encipher "PROGRAMMING PRAXIS" 4) "PMPRAM RSORIGAIGNX" > (decipher "PMPRAM RSORIGAIGNX" 4) "PROGRAMMING PRAXIS" We can test the functions using assert; remember that, with the assert macro, no news is good news: (do ((i 2 (+ i 1))) ((< 18 i))   (assert (decipher (encipher "PROGRAMMING PRAXIS" i) i)           "PROGRAMMING PRAXIS")) We use take, drop, range, filter, make-list, sort and assert from the Standard Prelude. We also use the utility function (transpose m), which transposes the rows and columns of a list of lists: (define (transpose m)   (if (null? (car m)) '()     (cons (map car m) (transpose (map cdr m))))) You can run this program at http://programmingpraxis.codepad.org/9abH1QKb. (function(g){g.__ATA.initAd({sectionId:26942, width:300, height:250});})(window); Like this:Like Loading... Related Pages: 1 2 ```
``` Posted by programmingpraxis Filed in Exercises 9 Comments » ```
``` 9 Responses to “Rail-Fence Cipher” FalconNL said March 31, 2009 at 3:06 PM In Haskell: import Data.List main = do print \$ rail 4 "PROGRAMMING PRAXIS" print . derail 4 \$ rail 4 "PROGRAMMING PRAXIS" rail :: Int -> String -> String rail n s = map (s !!) \$ waves n s derail :: Int -> String -> String derail n s = map snd . sort \$ zip (waves n s) s waves :: Int -> String -> [Int] waves n = map snd . sort . zip (cycle \$ [1..n] ++ [n-1,n-2..2]) . zipWith const [0..] matthias said April 1, 2009 at 2:31 PM FalconNL, your design turns the solution into “Fortran”, using indexes into lists (of chars) where a generative-recursion design (for freshmen) exposes the waves as they come about. Then again, you demonstrate how temporary laziness in ‘waves’ is a useful tool. Let me show you how temporary, invisible assignments accomplish the exact same purpose. ;; [Listof X] Nat -> [Listof X] ;; 1 5 9 ;; 1 2 3 4 5 6 7 8 9 10 11 ==> 2 4 6 8 10 ==> 1 5 9 2 4 6 8 10 3 7 11 ;; 3 7 11 (check-expect (fence ‘(1 2 3 4 5 6) 3) ‘(1 5 2 4 6 3)) (check-expect (fence ‘(1 2 3 4 5 6 7 8 9 10 11) 3) ‘(1 5 9 2 4 6 8 10 3 7 11)) (define (fence s n) (define is (shared ((x (append (range 1 n) (range (- n 1) 2) x))) x)) (define wv (for/list ((c s)) (begin0 (list c (car is)) (set! is (cdr is))))) (map first (sort2 wv))) matthias said April 1, 2009 at 3:37 PM Oops, fence is a two-liner in PLT Scheme, too: (define (fence s n) (define is (shared ((x (append (range 1 n) (range (- n 1) 2) x))) x)) (map first (sort2 (for/list ((c s) (i (in-list is))) (list c i))))) FalconNL said April 2, 2009 at 9:40 AM Updated version that I believe should run in O(n log n) for both rail and derail (rail was O(n^2) in the previous version): import Data.List import GHC.Exts main = do print \$ rail 4 "PROGRAMMING PRAXIS" print . derail 4 \$ rail 4 "PROGRAMMING PRAXIS" rail :: Int -> [a] -> [a] rail n = zipSort (cycle \$ [1..n] ++ [n-1,n-2..2]) derail :: Ord a => Int -> [a] -> [a] derail n s = zipSort (rail n \$ zipWith const [0..] s) s zipSort :: Ord a => [a] -> [b] -> [b] zipSort ks = map snd . sortWith fst . zip ks Luis Sergio Oliveira said May 17, 2009 at 5:03 PM Hi, my solution in Common Lisp, including some tests is here: http://lisp.pastebin.com/f27e23d44. Notice that I haven’t followed the algorithm proposed in your solution which is indeed very interesting… Thanks for the problem, Luis programmingpraxis said May 22, 2009 at 4:50 AM Posted on behalf of Matthias Felleisen: “I have finally found some time to write up my version of the story which only starts with the post here as a way to explain the idea in a first-semester FP course — with design principles. In contrast to the Haskell solution, mine is linear. If a linear purely FP solution exists, I’d like to know.” Programming Praxis – Double Transposition Cipher « Bonsai Code said May 30, 2009 at 3:49 PM […] up we have zipSort, which I also used in the Rail-Fence Cipher […] Jan Van lent said July 6, 2009 at 11:08 PM Common Lisp solution at http://paste.lisp.org/display/83135. ftt said February 27, 2014 at 10:46 PM https://github.com/ftt/programming-praxis/blob/master/20090331-rail-fence-cipher/rail-fence-cipher.py Leave a Reply Enter your comment here... Fill in your details below or click an icon to log in: Email (required) (Address never made public) Name (required) Website You are commenting using your WordPress.com account. ( Log Out / Change ) You are commenting using your Twitter account. ( Log Out / Change ) You are commenting using your Facebook account. ( Log Out / Change ) You are commenting using your Google+ account. ( Log Out / Change ) Cancel Connecting to %s var highlander_expando_javascript = function(){ var input = document.createElement( 'input' ), comment = jQuery( '#comment' ); if ( 'placeholder' in input ) { comment.attr( 'placeholder', jQuery( '.comment-textarea label' ).remove().text() ); } // Expando Mode: start small, then auto-resize on first click + text length jQuery( '#comment-form-identity' ).hide(); jQuery( '#comment-form-subscribe' ).hide(); jQuery( '#commentform .form-submit' ).hide(); comment.css( { 'height':'10px' } ).one( 'focus', function() { var timer = setInterval( HighlanderComments.resizeCallback, 10 ) jQuery( this ).animate( { 'height': HighlanderComments.initialHeight } ).delay( 100 ).queue( function(n) { clearInterval( timer ); HighlanderComments.resizeCallback(); n(); } ); jQuery( '#comment-form-identity' ).slideDown(); jQuery( '#comment-form-subscribe' ).slideDown(); jQuery( '#commentform .form-submit' ).slideDown(); }); } jQuery(document).ready( highlander_expando_javascript ); Notify me of new comments via email. Notify me of new posts via email. ```
``` Categories Administrivia Exercises Archives December 2015 November 2015 October 2015 September 2015 August 2015 July 2015 June 2015 May 2015 April 2015 March 2015 February 2015 January 2015 December 2014 November 2014 October 2014 September 2014 August 2014 July 2014 June 2014 May 2014 April 2014 March 2014 February 2014 January 2014 December 2013 November 2013 October 2013 September 2013 August 2013 July 2013 June 2013 May 2013 April 2013 March 2013 February 2013 January 2013 December 2012 November 2012 October 2012 September 2012 August 2012 July 2012 June 2012 May 2012 April 2012 March 2012 February 2012 January 2012 December 2011 November 2011 October 2011 September 2011 August 2011 July 2011 June 2011 May 2011 April 2011 March 2011 February 2011 January 2011 December 2010 November 2010 October 2010 September 2010 August 2010 July 2010 June 2010 May 2010 April 2010 March 2010 February 2010 January 2010 December 2009 November 2009 October 2009 September 2009 August 2009 July 2009 June 2009 May 2009 April 2009 March 2009 February 2009 March 2009 S M T W T F S « Feb   Apr » 1234567 891011121314 15161718192021 22232425262728 293031   Archives December 2015 November 2015 October 2015 September 2015 August 2015 July 2015 June 2015 May 2015 April 2015 March 2015 February 2015 January 2015 December 2014 November 2014 October 2014 September 2014 August 2014 July 2014 June 2014 May 2014 April 2014 March 2014 February 2014 January 2014 December 2013 November 2013 October 2013 September 2013 August 2013 July 2013 June 2013 May 2013 April 2013 March 2013 February 2013 January 2013 December 2012 November 2012 October 2012 September 2012 August 2012 July 2012 June 2012 May 2012 April 2012 March 2012 February 2012 January 2012 December 2011 November 2011 October 2011 September 2011 August 2011 July 2011 June 2011 May 2011 April 2011 March 2011 February 2011 January 2011 December 2010 November 2010 October 2010 September 2010 August 2010 July 2010 June 2010 May 2010 April 2010 March 2010 February 2010 January 2010 December 2009 November 2009 October 2009 September 2009 August 2009 July 2009 June 2009 May 2009 April 2009 March 2009 February 2009 Blogroll WordPress.com WordPress.org ```
``` The Ambiru Theme. Create a free website or blog at WordPress.com. /* <![CDATA[ */ var HighlanderComments = {"loggingInText":"Logging In\u2026","submittingText":"Posting Comment\u2026","postCommentText":"Post Comment","connectingToText":"Connecting to %s","commentingAsText":"%1\$s: You are commenting using your %2\$s account.","logoutText":"Log Out","loginText":"Log In","connectURL":"https:\/\/programmingpraxis.wordpress.com\/public.api\/connect\/?action=request","logoutURL":"https:\/\/programmingpraxis.wordpress.com\/wp-login.php?action=logout&_wpnonce=13b1b7723f","homeURL":"http:\/\/programmingpraxis.com\/","postID":"350","gravDefault":"blank","enterACommentError":"Please enter a comment","enterEmailError":"Please enter your email address here","invalidEmailError":"Invalid email address","enterAuthorError":"Please enter your name here","gravatarFromEmail":"This picture will show whenever you leave a comment. Click to customize it.","logInToExternalAccount":"Log in to use details from one of these accounts.","change":"Change","changeAccount":"Change Account","comment_registration":"","userIsLoggedIn":"","isJetpack":"0","text_direction":"ltr"}; /* ]]> */ Follow Follow “Programming Praxis” Get every new post delivered to your Inbox. Join 701 other followers Build a website with WordPress.com %d bloggers like this: //<![CDATA[ var jetpackLikesWidgetQueue = []; var jetpackLikesWidgetBatch = []; var jetpackLikesMasterReady = false; function JetpackLikespostMessage( message, target ) { if ( "string" === typeof message ){ try{ message = JSON.parse( message ); } catch(e) { return; } } pm( { target: target, type: 'likesMessage', data: message, origin: '*' } ); } function JetpackLikesBatchHandler() { var requests = []; jQuery( 'div.jetpack-likes-widget-unloaded' ).each( function( i ) { if ( jetpackLikesWidgetBatch.indexOf( this.id ) > -1 ) return; jetpackLikesWidgetBatch.push( this.id ); var regex = /like-(post|comment)-wrapper-(\d+)-(\d+)-(\w+)/; var match = regex.exec( this.id ); if ( ! match || match.length != 5 ) return; var info = { blog_id: match[2], width: this.width }; if ( 'post' == match[1] ) { info.post_id = match[3]; } else if ( 'comment' == match[1] ) { info.comment_id = match[3]; } info.obj_id = match[4]; requests.push( info ); }); if ( requests.length > 0 ) { JetpackLikespostMessage( { event: 'initialBatch', requests: requests }, window.frames['likes-master'] ); } } function JetpackLikesMessageListener( event ) { if ( "undefined" == typeof event.event ) return; if ( 'masterReady' == event.event ) { jQuery( document ).ready( function() { jetpackLikesMasterReady = true; var stylesData = { event: 'injectStyles' }; if ( jQuery( 'iframe.admin-bar-likes-widget' ).length > 0 ) { JetpackLikespostMessage( { event: 'adminBarEnabled' }, window.frames[ 'likes-master' ] ); stylesData.adminBarStyles = { background: jQuery( '#wpadminbar .quicklinks li#wp-admin-bar-wpl-like > a' ).css( 'background' ), isRtl: ( 'rtl' == jQuery( '#wpadminbar' ).css( 'direction' ) ) }; } if ( !window.addEventListener ) jQuery( '#wp-admin-bar-admin-bar-likes-widget' ).hide(); stylesData.textStyles = { color: jQuery( '.sd-text-color').css( 'color' ), fontFamily: jQuery( '.sd-text-color' ).css( 'font-family' ), fontSize: jQuery( '.sd-text-color' ).css( 'font-size' ), direction: jQuery( '.sd-text-color' ).css( 'direction' ), fontWeight: jQuery( '.sd-text-color' ).css( 'font-weight' ), fontStyle: jQuery( '.sd-text-color' ).css( 'font-style' ), textDecoration: jQuery( '.sd-text-color' ).css('text-decoration') }; stylesData.linkStyles = { color: jQuery( '.sd-link-color' ).css('color'), fontFamily: jQuery( '.sd-link-color' ).css('font-family'), fontSize: jQuery( '.sd-link-color' ).css('font-size'), textDecoration: jQuery( '.sd-link-color' ).css('text-decoration'), fontWeight: jQuery( '.sd-link-color' ).css( 'font-weight' ), fontStyle: jQuery( '.sd-link-color' ).css( 'font-style' ) }; JetpackLikespostMessage( stylesData, window.frames[ 'likes-master' ] ); JetpackLikesBatchHandler(); jQuery( document ).on( 'inview', 'div.jetpack-likes-widget-unloaded', function() { jetpackLikesWidgetQueue.push( this.id ); }); }); } if ( 'showLikeWidget' == event.event ) { jQuery( '#' + event.id + ' .post-likes-widget-placeholder' ).fadeOut( 'fast', function() { jQuery( '#' + event.id + ' .post-likes-widget' ).fadeIn( 'fast', function() { JetpackLikespostMessage( { event: 'likeWidgetDisplayed', blog_id: event.blog_id, post_id: event.post_id, obj_id: event.obj_id }, window.frames['likes-master'] ); }); }); } if ( 'clickReblogFlair' == event.event ) { wpcom_reblog.toggle_reblog_box_flair( event.obj_id ); } if ( 'showOtherGravatars' == event.event ) { var \$container = jQuery( '#likes-other-gravatars' ); var \$list = \$container.find( 'ul' ); \$container.hide(); \$list.html( '' ); \$container.find( '.likes-text span' ).text( event.total ); jQuery.each( event.likers, function( i, liker ) { \$list.append( '<li class="' + liker.css_class + '"><a href="' + liker.profile_URL + '" class="wpl-liker" rel="nofollow" target="_parent"><img src="' + liker.avatar_URL + '" alt="' + liker.name + '" width="30" height="30" style="padding-right: 3px;" /></a></li>'); } ); var offset = jQuery( "[name='" + event.parent + "']" ).offset(); \$container.css( 'left', offset.left + event.position.left - 10 + 'px' ); \$container.css( 'top', offset.top + event.position.top - 33 + 'px' ); var rowLength = Math.floor( event.width / 37 ); var height = ( Math.ceil( event.likers.length / rowLength ) * 37 ) + 13; if ( height > 204 ) { height = 204; } \$container.css( 'height', height + 'px' ); \$container.css( 'width', rowLength * 37 - 7 + 'px' ); \$list.css( 'width', rowLength * 37 + 'px' ); \$container.fadeIn( 'slow' ); var scrollbarWidth = \$list[0].offsetWidth - \$list[0].clientWidth; if ( scrollbarWidth > 0 ) { \$container.width( \$container.width() + scrollbarWidth ); \$list.width( \$list.width() + scrollbarWidth ); } } } pm.bind( 'likesMessage', function(e) { JetpackLikesMessageListener(e); } ); jQuery( document ).click( function( e ) { var \$container = jQuery( '#likes-other-gravatars' ); if ( \$container.has( e.target ).length === 0 ) { \$container.fadeOut( 'slow' ); } }); function JetpackLikesWidgetQueueHandler() { var wrapperID; if ( ! jetpackLikesMasterReady ) { setTimeout( JetpackLikesWidgetQueueHandler, 500 ); return; } if ( jetpackLikesWidgetQueue.length > 0 ) { // We may have a widget that needs creating now var found = false; while( jetpackLikesWidgetQueue.length > 0 ) { // Grab the first member of the queue that isn't already loading. wrapperID = jetpackLikesWidgetQueue.splice( 0, 1 )[0]; if ( jQuery( '#' + wrapperID ).hasClass( 'jetpack-likes-widget-unloaded' ) ) { found = true; break; } } if ( ! found ) { setTimeout( JetpackLikesWidgetQueueHandler, 500 ); return; } } else if ( jQuery( 'div.jetpack-likes-widget-unloaded' ).length > 0 ) { // Grab any unloaded widgets for a batch request JetpackLikesBatchHandler(); // Get the next unloaded widget wrapperID = jQuery( 'div.jetpack-likes-widget-unloaded' ).first()[0].id; if ( ! wrapperID ) { // Everything is currently loaded setTimeout( JetpackLikesWidgetQueueHandler, 500 ); return; } } if ( 'undefined' === typeof wrapperID ) { setTimeout( JetpackLikesWidgetQueueHandler, 500 ); return; } var \$wrapper = jQuery( '#' + wrapperID ); \$wrapper.find( 'iframe' ).remove(); if ( \$wrapper.hasClass( 'slim-likes-widget' ) ) { \$wrapper.find( '.post-likes-widget-placeholder' ).after( "<iframe class='post-likes-widget jetpack-likes-widget' name='" + \$wrapper.data( 'name' ) + "' height='22px' width='68px' frameBorder='0' scrolling='no' src='" + \$wrapper.data( 'src' ) + "'></iframe>" ); } else { \$wrapper.find( '.post-likes-widget-placeholder' ).after( "<iframe class='post-likes-widget jetpack-likes-widget' name='" + \$wrapper.data( 'name' ) + "' height='55px' width='100%' frameBorder='0' src='" + \$wrapper.data( 'src' ) + "'></iframe>" ); } \$wrapper.removeClass( 'jetpack-likes-widget-unloaded' ).addClass( 'jetpack-likes-widget-loading' ); \$wrapper.find( 'iframe' ).load( function( e ) { var \$iframe = jQuery( e.target ); \$wrapper.removeClass( 'jetpack-likes-widget-loading' ).addClass( 'jetpack-likes-widget-loaded' ); JetpackLikespostMessage( { event: 'loadLikeWidget', name: \$iframe.attr( 'name' ), width: \$iframe.width() }, window.frames[ 'likes-master' ] ); if ( \$wrapper.hasClass( 'slim-likes-widget' ) ) { \$wrapper.find( 'iframe' ).Jetpack( 'resizeable' ); } }); setTimeout( JetpackLikesWidgetQueueHandler, 250 ); } JetpackLikesWidgetQueueHandler(); //]]> (function(){ var corecss = document.createElement('link'); var themecss = document.createElement('link'); var corecssurl = "http://s0.wp.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css?m=1422342134g&amp;ver=3.0.9b"; if ( corecss.setAttribute ) { corecss.setAttribute( "rel", "stylesheet" ); corecss.setAttribute( "type", "text/css" ); corecss.setAttribute( "href", corecssurl ); } else { corecss.rel = "stylesheet"; corecss.href = corecssurl; } document.getElementsByTagName("head")[0].insertBefore( corecss, document.getElementById("syntaxhighlighteranchor") ); var themecssurl = "http://s0.wp.com/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shThemeDefault.css?m=1363304414g&amp;ver=3.0.9b"; if ( themecss.setAttribute ) { themecss.setAttribute( "rel", "stylesheet" ); themecss.setAttribute( "type", "text/css" ); themecss.setAttribute( "href", themecssurl ); } else { themecss.rel = "stylesheet"; themecss.href = themecssurl; } //document.getElementById("syntaxhighlighteranchor").appendChild(themecss); document.getElementsByTagName("head")[0].insertBefore( themecss, document.getElementById("syntaxhighlighteranchor") ); })(); SyntaxHighlighter.config.strings.expandSource = '+ expand source'; SyntaxHighlighter.config.strings.help = '?'; SyntaxHighlighter.config.strings.alert = 'SyntaxHighlighter\n\n'; SyntaxHighlighter.config.strings.noBrush = 'Can\'t find brush for: '; SyntaxHighlighter.config.strings.brushNotHtmlScript = 'Brush wasn\'t configured for html-script option: '; SyntaxHighlighter.defaults['pad-line-numbers'] = false; SyntaxHighlighter.defaults['toolbar'] = false; SyntaxHighlighter.all(); // <![CDATA[ (function() { try{ if ( window.external &&'msIsSiteMode' in window.external) { if (window.external.msIsSiteMode()) { var jl = document.createElement('script'); jl.type='text/javascript'; jl.async=true; jl.src='/wp-content/plugins/ie-sitemode/custom-jumplist.php'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(jl, s); } } }catch(e){} })(); // ]]> _tkq = window._tkq || []; _stq = window._stq || []; _tkq.push(['storeContext', {'blog_id':'6649073','blog_tz':'0','user_lang':'en','blog_lang':'en','user_id':'0'}]); _stq.push(['view', {'blog':'6649073','v':'wpcom','tz':'0','user_id':'0','post':'350','subd':'programmingpraxis'}]); _stq.push(['extra', {'crypt':'UE5XaGUuOTlwaD85flAmcm1mcmZsaDhkV11YdWtpP0NsWnVkPS9sL0ViLndld3AlSGN8YmRCSmtFZUxRR1lZc2ZadVg3cTBuL0VLL1ZwbmhsV0hlUFdwMm1rVGptMmJ8Wj1yP2hVWGdYfDVDRDJDW1ZjUDdhbms9TGtvX2RkUDJTdCZPY2hTUDFKVDZhLT9RMWtpQzRBbDYvP1dzQktVaU1pb35CR1ZnUDJjN3RjUkw9VXNKVFBaPTd6Yl1bTmZvQnlNdCs1KzFDZTM0TU1qdVJTbURYflQlOGZXXyZtWE1uMytbdl04ekloT09VT1NfZ19SJi1qNjl5cWFvfjMlUmFKVVpZS3pINXpZLVo5UU0/LmN6MW5LJWJIK2srWHZxJnV0Lg=='}]); _stq.push([ 'clickTrackerInit', '6649073', '350' ]); if ( 'object' === typeof wpcom_mobile_user_agent_info ) { wpcom_mobile_user_agent_info.init(); var mobileStatsQueryString = ""; if( false !== wpcom_mobile_user_agent_info.matchedPlatformName ) mobileStatsQueryString += "&x_" + 'mobile_platforms' + '=' + wpcom_mobile_user_agent_info.matchedPlatformName; if( false !== wpcom_mobile_user_agent_info.matchedUserAgentName ) mobileStatsQueryString += "&x_" + 'mobile_devices' + '=' + wpcom_mobile_user_agent_info.matchedUserAgentName; if( wpcom_mobile_user_agent_info.isIPad() ) mobileStatsQueryString += "&x_" + 'ipad_views' + '=' + 'views'; if( "" != mobileStatsQueryString ) { new Image().src = document.location.protocol + '//pixel.wp.com/g.gif?v=wpcom-no-pv' + mobileStatsQueryString + '&baba=' + Math.random(); } } ```