text:
Encode the alphabet cipher
Given a string that contains only lowercase letters, encode that string with the alphabet cipher.
To encode with the alphabet cipher (I will be using the example hello):

First, convert each letter in the string to a number depending on its position in the alphabet (a = 1, b = 2, etc.) Example: 8 5 12 12 15
Pad each number to two characters with 0s. Example: 08 05 12 12 15
Join. Example: 0805121215

Test cases
helloworld -> 08051212152315181204
codegolf -> 0315040507151206
alphabetcipher -> 0112160801020520030916080518
johncena -> 1015081403051401

Remember, this is code-golf, so the code with the fewest number of bytes wins.

Related.

05AB1E, 11 6 bytes
Code:
Ç4+€¦J

Explanation:
First, we convert the string to their ASCII values. codegolf would become:
[99, 111, 100, 101, 103, 111, 108, 102]

To get to the indices of the alphabet, you subtract 96:
[3, 15, 4, 5, 7, 15, 12, 6]

To pad with zeros, add 100 to each element and remove the first character of each int. For the above example, +100 would be:
[103, 115, 104, 105, 107, 115, 112, 106]

And removing the first character of each would lead to:
[03, 15, 04, 05, 07, 15, 12, 06]

We can merge both steps above (the -96 and the +100) part to just +4. For the code:
Ç       # Convert to an array of ASCII code points
 4+     # Add four to each element in the array
   €¦   # Remove the first character of each element
     J  # Join to a single string

Try it online!

What does ¦ do again?

@carusocomputing Removes the first element of a string, list, etc.

Beyond genius...

Python 2, 42 bytes
f=lambda s:s and`ord(s[0])+4`[1:]+f(s[1:])

Test it on Ideone.

Non recursive, same byte count: lambda s:''.join(`ord(x)+4`[1:]for x in s)

C, 55 43 bytes
f(char*c){for(;*c;)printf("%02d",*c++-96);}

ideone

printf("%02d",*c++-96);} is shorter and valid if I'm not mistaken.

Pyth, 11 10 bytes
FNwpt`+4CN

Try it! My first go at Pyth.
FNwpt`+4CN
FNw         # For N in w (w is input, N will be single char)
   p        # Print without newline
        CN  # Int with code point `N`
      +4CN  # Add 4 to int with code point N
     `+4CN  # representation of above (basically to string)
    t`+4CN  # Tail (All but first character)

Python equivalent:
for N in input():
    print(repr(ord(N) + 4)[1:], end='')

Good job on your first Pyth program!

Python, 46 bytes
lambda x:"".join("%02i"%(ord(j)-96)for j in x)

Pretty straightforward. Try it on repl.it!

Wow, two completely different attempts with the same byte count ;)

Jelly, 9 7 bytes
O+4ṾḊ$€

TryItOnline
How?
O+4ṾḊ$€ - Main link: s                                e.g. hello
O       - cast to ordinals                            e.g. [ 104,  101,  108,  108,  111]
 +4     - add 4                                       e.g. [  108,  109,  112,  112,  115]
     $€ - last two links as a monad for €ach
   Ṿ    -    uneval, effectively converts to strings  e.g. ["108","109","112","112","115"]
    Ḋ   -    dequeue, remove the leading '1'          e.g. [ "08", "09", "12", "12", "15"]
        - implicit print                              e.g. "0809121215"

I came up with O+4DḊ€FṾ€ for the same count, perhaps golfable

@ETHproductions O+4Ṿ€Ḋ€ saves 2 bytes.

@Dennis I just did the same (ish)...

Haskell, fortyfour 30 28 bytes
(>>=tail.show.(+4).fromEnum)

Using the +4 approach from Adnan's answer saves 14 bytes.
Try it on Ideone. Usage:
> (>>=tail.show.(+4).fromEnum)"codegolf"
"0315040507151206"

Two bytes off thanks to xnor. Old version:
f a=['0'|a<'k']++(show$fromEnum a-96)
(f=<<)

You don't need the second set of parens.

JavaScript (ES6), 52 49 bytes
f=s=>s&&(s.charCodeAt()+4+f(s.slice(1))).slice(1)

Recursion turned out to be 3 bytes shorter than .replace:
s=>s.replace(/./g,s=>(s.charCodeAt()+4+"").slice(1))

parseInt(s,36) is slightly longer for each approach, because you have to change 4 to 91:
s=>s.replace(/./g,s=>(parseInt(s,36)+91+"").slice(1))
f=s=>s&&(parseInt(s[0],36)+91+f(s.slice(1))).slice(1)

Perl, 29 bytes
28 bytes of code + -n flag.
printf"%02s",-96+ord for/./g

Run with :
perl -ne 'printf"%02s",-96+ord for/./g' <<< "helloworld"

25 bytes (or 27 under the rules at the time of this challenge): Try it online!

Japt, 10 bytes
¡4+Xc)s s1

Probably doesn't get shorter than this...
Test it online!
Explanation
¡           // Map each char X in the input by this function:
 4+Xc)      //   Take 4 + the char code of X.
      s s1  //   Convert to a string, then remove the first char.
            // Implicit: output last expression

MATL, 12 11 bytes
1 byte saved thanks to @Luis
4+!V4LZ)!le

Try it Online

Java 7,60 bytes
void f(char[]s){for(int i:s)System.out.printf("%02d",i-96);}

This answer might not be valid because it takes a char[] instead of a String.

@AlexL. Lists of characters are considered strings.

@MartinEnder Okay. Thank you for the clarification. This answer has my upvote.

Hexagony, 33 bytes
10}{'a({=!{{\.@29$\,<.-":!\>Oct\%

Try it Online!
Mm.. got a few no-ops in the Hexagon so I put today's date in.
Expanded Form with date replaced by no-ops
   1 0 } {
  ' a ( { =
 ! { { \ . @
. . $ \ , < .
 - " : ! \ >
  . . . \ %
   . . . .

Initialise a 10 and move Memory Pointer to somewhere...
$ skips the mirror and , reads a byte. < branches:
If end of string (-1 which is non-positive) it goes to @ and terminates the program.
Otherwise it subtracts 95 (decremented a), and then we print result / 10 (integer division) and result % 10 and loop again.

Stax, 5 bytes
öÇIªÆ

Run and debug it
For each character

add 4 to the codepoint e.g. 108
convert to string e.g. "108"
drop the first character e.g. "08"

APL (Dyalog Unicode), 19 12 bytes SBCS
        ⎕UCS  ⍝ Convert the argument (string) into an array of codepoints.
      4+      ⍝ and add 4 to each of those codepoints.
     ¨        ⍝ Now, for each of those numbers
    ⍕         ⍝ turn it into a string
   ∘          ⍝ and
 1↓           ⍝ drop its first character.
∊             ⍝ Finally enlist the strings into a single string (as in, join them together)

Thanks @Bubbler for saving 7 bytes
my original 19 bytes
{,/{1↓⍕⍵}¨4+⎕UCS ⍵}

Try it online!
{                   } ⍝ Define a function taking a string as argument.
             ⎕UCS ⍵  ⍝ Convert the argument (string) into an array of codepoints.
           4+         ⍝ and add 4 to each of those codepoints.
   {     }¨           ⍝ For each number in the array,
      ⍕⍵             ⍝ convert it to a string
    1↓                ⍝ and drop the first character (the 1).
 ,/                   ⍝ Finally join everything and return.

12 bytes. Check out the successive transformations to shorten the code.

@Bubbler thanks for the step-by-step! I'll read what those glyphs you introduced do, and then update my answer!

@Bubbler If I understand correctly, ∊ is acting as some sort of "flatten" right? Because I have a list of strings, i.e. a list of lists of characters, and then the enlist operator turns everything into a 1d array?

Vyxal s, 6 bytes
C4+ƛSḢ

-1 byte thanks to @Steffan
Try it Online!
Explanation:
C       # Convert to ASCII codes
 4+     # Add 4
   ƛ    # On each number:
    S   #   Stringify
     Ḣ  #   Remove first char

Try it Online! for 6 bytes.

@Steffan Cool approach, thank you!

Perl, 24 bytes
Includes +1 for -p
Give input on STDIN:
encode.pl <<< hello

encode.pl
#!/usr/bin/perl -p
s/./substr 4+ord$&,1/eg

Nicely done. I think you probably meant 4+ord$& instead of 5+ord$& though ;-)

@Dada Right, pasted the version of my snippet buffer instead of the tested version again

It happens! :) Could I ask you an unrelated question? Do you have any idea what is the 8 bytes perl solution to this question (reverse the input) (on anarchy) ?

@Dada I'd say it is impossible in pure perl, so I expect it's some abuse of the automated system on that side. E.g. if input came from STDIN you could do exec rev

Right, that makes sense, thanks! I was having a hard time figuring this out since print is 5 bytes, <> is 2 more, so I was wondering what was the 1 byte builtin to reverse I hadn't heard of!

Vim, 60 keystrokes
:s/./\=char2nr(submatch(0))-96."\r"/g
:%s/\<\d\n/0&
V{gJ

An almost entirely regex based solution. As usual, using the eval register makes it obscenely long.

Batch, 256 239 237 bytes
@echo off
set/ps=
set r=
set a=abcdefghijklmnopqrstuvwxyz
:g
set c=%a%
for /l %%i in (101,1,126)do call:l %%i
set s=%s:~1%
if not "%s%"=="" goto g
echo %r%
exit/b
:l
set i=%1
if %c:~,1%==%s:~,1% set r=%r%%i:~1%
set c=%c:~1%

Takes input on STDIN.

PHP, 58 Bytes
foreach(str_split($argv[1])as$c)printf("%02d",ord($c)%32);

you can -8 bytes iterating as a string 50 bytes TIO, or -11 bytes input via $argn 47 bytes TIO.

PowerShell v2+, 44 bytes
-join([char[]]$args[0]|%{"{0:D2}"-f($_%32)})

Takes input $args[0], casts it as a char-array, feeds into a loop. Each iteration, we take the current character $_ modulo 32, which implicitly casts as the ASCII value. Conveniently ;-), this lines up so a = 1, b = 2, etc. That fed into the -format operator, operating on string "{0:D2}", which specifies a two digit minimum (i.e., it prepends a leading zero if required). Those strings of digits are encapsulated in parens, -joined together into one string, and left on the pipeline. Output via implicit Write-Output happens at program conclusion.
PS C:\Tools\Scripts\golfing> .\encode-alphabet-cipher.ps1 'hello'
0805121215

PS C:\Tools\Scripts\golfing> .\encode-alphabet-cipher.ps1 'helloworld'
08051212152315181204

PS C:\Tools\Scripts\golfing> .\encode-alphabet-cipher.ps1 'codegolf'
0315040507151206

PS C:\Tools\Scripts\golfing> .\encode-alphabet-cipher.ps1 'johncena'
1015081403051401

DASH, 27 bytes
@><""(->@rstr["."""]+4#0)#0

Example usage:
(@><""(->@rstr["."""]+4#0)#0)"helloworld"

Explanation
@ (                         #. take input through a lambda
  join "" (                 #. join with newlines the following:
    (map                    #. result of mapping
      @ (                   #. this lambda
        rstr ["." ; ""] (     #. replace first char w/ empty string:
          + 4 #0               #. mapped item's codepoint + 4
        )
      )
    ) #0                    #. over the argument
  )
)

IBM PC DOS 8088 Assembly, 33 28 27 bytes
Assembled binary:
00000000: be82 00ac 2c60 7812 d40a 0530 3092 86f2  ....,`x....00...
00000010: b402 cd21 86f2 cd21 ebe9 c3              ...!...!...

Unassembled:
BE 0082     MOV  SI, 82H        ; point SI to command line string
        CH_LOOP:
AC          LODSB               ; load next char into AL
2C 60       SUB  AL, 'a'-1      ; convert ASCII to a=1,b=2...z=26
78 12       JS   DONE           ; if char is terminator or not valid, exit
D4 0A       AAM                 ; convert binary to BCD
05 3030     ADD  AX, '00'       ; convert BCD to ASCII
92          XCHG DX, AX         ; save AX to DX for display
86 F2       XCHG DH, DL         ; reverse bytes
B4 02       MOV  AH, 2          ; DOS display char function
CD 21       INT  21H            ; write first digit
86 F2       XCHG DH, DL         ; reverse bytes back
CD 21       INT  21H            ; write second digit
EB E9       JMP  CH_LOOP        ; restart loop
        DONE:
C3          RET                 ; return to DOS

Standalone PC DOS executable.  Input string from command line, output to console.
I/O:

Piet + ascii-piet, 44 bytes (2×22=44 codels)
tuuuumknnfbkqmkcalrmu_sajs?daltdddbfckkkkk ?

Try Piet online!
Input the string with the sentinel value _.
Pseudocode
while true:
  S = character input
  n = (codepoint of S) - 96
  if n+1 == 0:
    exit
  else:
    print(floor(n/10))
    print(n modulo 10)

BQN, 16 bytes
∾·(1↓•Fmt)¨4+-⟜@

Try it at BQN online!
Explanation
Same approach, independently derived, as RGS's APL answer and tybocopperkettle's Vyxal s answer.
∾·(1↓•Fmt)¨4+-⟜@
             -⟜@  Subtract null byte from each character, giving its ASCII value
           4+      Add 4 (a = 101, z = 126)
  (      )¨        Map this function to each number:
     •Fmt            Format as string
   1↓                Drop first character
∾·                Join together into a single string

J, 25 22 15 bytes
[:,4}.@":@+3&u:

Try it online!
-7 bytes thanks to ngn's K approach

K (ngn/k), 8 bytes
,/1_'$4+

Try it online!
4+ add 4 to (the ASCII codes of) the argument - this turns a into 101, b into 102, etc
$ format numbers as strings
1_' drop one digit from each
,/ concatenate

Mind adding an explanation?

done

Oh that’s clever!

not much different from other array-lang solutions, to be honest

Just saved me 7 bytes ¯\(ツ)/¯

Knight, 45 41 bytes
-4 thanks Aiden
;=xP W<1Lx;O++*'0'-2L=a-Ax 96a'\'=xSxF1""

Try it online!

Instead of A GxF1 you can simply do Ax, because ASCII already returns the ascii value of the first character in the string.

Nice trick using SxF1 instead of Gx 1Lx

@Steffan SxF1"" and Gx 1Lx are the same bytecount and do the same thing, so it's just two different ways to do the same thing.

Oh, for some reason I missed the "" lol

Labyrinth, 40 bytes
      ,")@
!{_10%! (
/       _
01_}:-69"

Actually, 10 bytes
Using the neat algorithm in Adnan's 05AB1E answer. Golfing suggestions welcome. Try it online!
O4+`$pX`MΣ

Ungolfing
         Implicit input s.
O        ord() every char in s.
4+       Add 4 to every ord in s.
`...`M   Map the following function over s. Variable m.
  $        Push str(m).
  pX       Discard the first char of str(m).
           Invariably this is a `1` and we get our ciphered m.
Σ        sum() everything to get one string.
         Implicit return.

MATL, 11 bytes
96-OH&YA!1e

Try it online!
         % Implicit input
96-      % Subtract 96. So 'a' becomes 1, 'b' becomes 2 etc
OH&YA    % Convert each number to 2 decimal digits. Gives a 2-column matrix
!1e      % Transpose and linearize into a row
         % Implicit display

Ruby, 53 46 bytes
->s{s.chars.map{|c|(c.ord-96).to_s.rjust(2,?0)}.join}
->s{s.chars.map{|c|(c.ord+4).to_s[1..2]}.join}

41 bytes: ->s{s.chars.map{|c|"#{c.ord+4}"[1,2]}*''}

R, 71 51 bytes
Saved 20 bytes thanks to Billywob. Takes input from stdin and outputs to stdout.
cat(sprintf("%02d",utf8ToInt(scan(,""))-96),sep="")

Examples:

helloworld -> 08051212152315181204
codegolf -> 0315040507151206
alphabetcipher -> 0112160801020520030916080518
johncena -> 1015081403051401

You can use utf8toInt(scan(,"))-96 instead of the whole match thing. Don't think there's a better way to handle the padding though.

@Billywob Thanks! For the padding, I tried using formatC earlier but that worked out as needing one more byte than the current approach.

Python 2, 51 49 45 42 bytes
lambda x:"".join(`ord(i)+4`[1:]for i in x)

Try it online!
Golfed to 49 bytes because .join will accept generators too
Golfed to 45 bytes because of lambdas
Golfed to 42 bytes because of switching to Python 2 and using `` (repr)
EXPLANATION:
Uses the trick in the 05AB1E answer.
lambda x:                               Declare a lambda accepting the string
    "".join(                            Join by the empty string
         `                              Repr (string representation)...
             ord(                       Unicode codepoint (A -> 65, a -> 97)
                 i                      The iterator in the for loop
             )
             + 4                        Added by 4
         `
         [1:]                           With the first character removed
    ) for i in x                        While a char i is in the string x

Powershell, 39 33 bytes
Inspired by AdmBorkBork's answer.
-6 bytes thanks @Julian
-join($args|%{'{0:D2}'-f($_-96)})

Try it online!

33 bytes using splatting ;)

Python 3, 47 bytes
f=lambda x:"".join(f"{ord(j)-96:02}"for j in x)

Try it online!

Whitespace, 84 bytes
[N
S S N
_Create_Label_LOOP][S S S N
_Push_0][S N
S _Dupe_0][T    N
T   S _Read_STDIN_as_char][T    T   T   _Retrieve_input][S S S T    T   S S S S S N
_Push_96][T S S T   _Subtract][S N
S _Dupe][S S S T    S T S N
_Push_10][T S S T   _Subtract][N
T   T   S N
_If_neg_jump_to_Label_PRINT_0][N
S S T   N
_Create_Label_DONE_WITH_PRINT_0][T  N
S T _Print_as_integer][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT_0][S S S N
_Push_0][T  N
S T _Print_as_integer][N
S N
T   N
_Jump_to_Label_DONE_WITH_PRINT_0]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Start LOOP:
  Integer c = STDIN as character
  c = c - 96
  If(c < 10):
    Print 0 as integer to STDOUT
  Print c as integer to STDOUT
  Go to next iteration of LOOP

K (oK), 13 bytes
Solution:
,//$3 10\'96!

Try it online!
Explanation:
,//$3 10\'96! / the solution
          96! / input modulo 96
    3 10\'    / convert to base 30ish
   $          / convert to string
,//           / flatten (,/) over (/)

Google Sheets, 76 bytes
=ArrayFormula(Join(,Text(Code(Mid(A1,Row(Indirect("1:"&Len(A1))),1))-96,"00"

Sheets will automatically add three closing parentheses when you exit the cell.
Input is in cell A1
Indirect("1:"&Len(A1)) returns a range as tall as the input is long.
Row(Indirect(~)) returns the row numbers, so it's a list of numbers from 1 to the input length.
Mid(A1,Row(~),1) returns each character from the input, one at a time.
Code(Mid(~))-96 returns the ASCII code for each character, down-shifted so a = 1.
Text(Code(~),"00") pads the result above to two digits.
Join(,Text(~)) joins all those padded results without a delimiter.
ArrayFormula(Join(~)) makes all the stuff above operate on arrays. Without, the result would just be the first padded alphabet code: helloworld would return 08.

Labyrinth, 27 bytes
 ,_9 @
%! 6-:
0    _
1_!/01

Try it online!
How it works
        Start at the first valid instruction, going right
,_96-:  Push a char, subtract 96, duplicate
@       If it's negative (EOF), turn left and terminate
        Otherwise it is positive. Turn right and follow the cycle
_10/!   Integer-divide by 10, pop and print as integer
_10%!   Modulo 10, pop and print as integer
        Re-enter the start of the program, looping until EOF

By replacing the second _1 with # and some careful twisting of the code, this can be 25 bytes

Oh, I realise that the # change did nothing, aince I have to add a no-op. It was just the rearrangement of the code that golfed bytes

K (ngn/k), 31 29 bytes
,/{$[1=#$x;"0",$x;$x]}'-96+0+

Try it online!
Another function-less answer.
Explanation:
,/{$[1=#$x;"0",$x;$x]}'-96+0+       Main function.
                           0+       Convert each character to ASCII value.
                       -96+         Add with -96 for each of them
                      '             For each of the numbers
  {                  }              Execute a function that
   $[               ]               If
        $x                          The number converted to string
       #                            Length
     1=                             Is equal to 1
          ;"0",$x                   Then, pad "0" before the number
                 ;$x                Else, return the number converted to string
,/                                  Join

Alice, 40 bytes
wi.hn$@'`-v
v o0'v$:a.<
v    <
>/ \K
  o

Try it online!
Flattened
wi.hn$@'`-.a:$v'0o>/o\K  Full solution
              >   ^      (additional redirections)

wi.hn$@               K  Where there are characters to read on the input
       '`-               Get the letter position in the alphabet
          .a:$v'0o       If it is less than 10, print a leading 0
                    o    Then print the number

Nibbles, 5.5 bytes (11 nibbles)
+.$>>`p+4o

Another port of Adnan's 05AB1E answer.
(Converting to base-10 digits and dropping the first one comes-out half-a-byte (1 nibble) longer: +.$>>`@~+4o).
 .$             # map over each character in the input:
   >>           #  drop the first element of
     `P         #  the string representation of
         o      #  the ASCII value
       +4       #  plus 4
+               # and finally concatenate it all

Pyke, 7 bytes
F.oOO`t

Try it here!
F       -  for i in input:
 .o     -       ord(i)
   OO   -      ^ + 4
     `  -     str(^)
      t -    ^[1:]
        - sum(^)

Groovy - 31 bytes
Groovy conversion of NumberKnot's solution in java:
{it.each{printf("%02d",it-96)}}
Example here using various options:
http://ideone.com/vd0dTX

Befunge-98, 19 bytes
#@~'`-:a/'0+,a%'0+,

Swift 3, 51
Dependency: Foundation for String(format:_:)
{$0.utf8.map{String(format:"%02d",$0-96)}.joined()} // where $0 is String
Usage:
Test
"codegolf".utf8.map{String(format:"%02d",$0-96)}.joined()
or
{$0.utf8.map{String(format:"%02d",$0-96)}.joined()}("codegolf")

C#, 54 bytes
s=>String.Join("",s.Select(n=>(n<106?"0":"")+(n-96)));

Groovy, 51 Bytes
{it.collect{(((int)it-96)+"").padLeft(2,"0")}.join()}

MATLAB / Octave, 32 24 bytes
@(s)sprintf('%02d',s-96)

Explanation

@(s) denotes an anonymous function whose input is expected to be a string and stored in the variable s.
The ASCII code for the letter a is 97.  Therefore, subtracting the input string by 96 coalesces the string so that it becomes an array transforming the string into an array of numbers enumerated from 1 to 26, so we're now at input('','s')-96.
Using sprintf with the formatting specifier %02d takes the numbers in the array and ensures that there are 2 digits to output for each number.  The numbers are thus combined to a single string and we output a single string. We will also pad the first digit with a 0 in case there is only 1 digit in an array.

Examples
>> f=@(s)sprintf('%02d',s-96)
>> f('helloworld')

ans =

08051212152315181204

>> f('codegolf')

ans =

0315040507151206

>> f('alphabetcipher')

ans =

0112160801020520030916080518

>> f('johncena')

ans =

1015081403051401

Try it online!
Try it here with ideone.

GolfSharp, 37 bytes
s=>s.s(n=>(n<106?"0":"")+(n-96)).j();

Dart, 58 bytes
f(s)=>s.runes.map((t)=>'${t-96}'.padLeft(2,'0')).join('');

Try it online!
Other 58 bytes solution :
f(s)=>s.runes.map((t)=>(t>106?'0':'')+'${t-96}').join('');

Try it online!

Rust, 197 191 181 bytes
|t:&String|->Option<String>{let a="abcdefghijklmnopqrstuvwxyz";let mut o=String::new();for c in t.chars(){let n=a.find(c)?+1;if n<10{o.push('0');}o.push_str(&n.to_string());}Some(o)

Reduced number of bytes thanks to Jonathan Fretch. Code should be runnable at https://repl.it/repls/RightMiniFunctions
Reduced number of bytes again thanks to ASCII-only.

Can you not save some bytes by removing whitespace in n < 10 or n = a.find(c)? Furthermore, would you mind adding a link to an online testing environment for ease of verification?

You should at least rename the function to a 1-character name. Also, lambdas (anonymous functions) are valid

C# (Visual C# Interactive Compiler), 43 bytes
n=>string.Concat(n.Select(c=>$"{c%32:D2}"))

Try it online!
Alternative taking in a List<char>, 36 bytes
n=>n.ForEach(c=>Write($"{c%32:D2}"))

Try it online!

List<char> is a valid way to take in a string

I know, I just thought of the alternative after my first solution so I put it after it

32 bytes with SelectMany (but returns an IEnumerable<char>).

Japt -m, 8 bytes
c +4 s Å

Run it online

MBASIC, 112 bytes
I could save 8 bytes on line 2 if STR$() didn't insist on including a leading space.
1 INPUT S$:FOR I=1 TO LEN(S$):A=ASC(MID$(S$,I,1))-96:IF A<10 THEN O$=O$+"0"
2 O$=O$+MID$(STR$(A),2):NEXT:PRINT O$

Sample output
? alphabetcipher
0112160801020520030916080518

GolfScript, 10 bytes
In GolfScript converting to a character is unneccecary because strings are character arrays.
{4+''+1>}%

Try it online!
Explanation
{       }% # Foreach over the implicit codepoint list
 4+        # Add 4 to every item of the list
   ''+     # Convert to a string
      1>   # Filter out all characters after the 1st character,
           # Including the 1st character

Erlang (escript), 39 bytes
The usual +4 approach.
f(X)->[tl(integer_to_list(I+4))||I<-X].

Try it online!

PowerShell, 99 bytes
([char[]]"$args"|%{"0$((@(65..90|%{[char]$_})-join'').indexof($_.tostring().toupper())+1)"})-join''

Try it online!

Acc!!, 55 bytes
N-6
Count i while _/5 {
Write _/10+39
Write _%10+48
N-6

Try it online!
Explanation
# Read a character, subtract 6 from its charcode, and store in the accumulator
N-6
# Loop while the character was not newline (i.e. the accumulator is >= 5)
Count i while _/5 {
  # Subtract 90 from the accumulator, divide by 10, and output as a digit
  Write (_-90)/10+48
  # Output the accumulator mod 10 as a digit
  Write _%10+48
  # Read the next character
  N-6
}

Knight, 49 bytes
;;;;=y""=xP=i 0W>+1Lx=i+1i=y+yG+4A Gx-i 1 1 1 2Oy

Try it online!
What a mess.
Ungolfed:
; = y ""
; = x PROMPT
; = i 0
; WHILE (> (+ 1 LENGTH (x)) (= i (+ 1 i))
    = y (+ y (GET (+ 4 (ASCII (GET x (- i 1) 1))) 1 2))
: OUTPUT y

brev, 57 bytes
(over(display(pop(number->string(+(char->integer x)4)))))

Everyone came up with the +4 ♀

CJam, 9 bytes
{i4+s1>}%

Try it online!
A function taking a string as input. Port of many other answers.
Explanation
{      }% # for each value in the input
 i        # convert it into a number
  4+      # add 4 to it
    s     # convert it to a string
     1>   # drop the first character

A version which isn't a port, for fun:
CJam, 11 bytes
{'`-sYTe[}%

Try it online!
Explanation
{        }% # map the following across the input
 '`-        # subtract the codepoint of '`', 96, from each value
    s       # convert to a string
       e[   # and pad the left with
      T     # 0s to length
     Y      # 2

Thunno 2 JB, 5 bytes
4+ıṘḣ

Attempt This Online!
Port of Adnan's 05AB1E answer.
Explanation
4+ıṘḣ  # Implicit input
       # Convert to codepoints
4+     # Add four
  ı    # Map:
   Ṙ   #  Convert to string
    ḣ  #  Remove the first item
       # Join the list
       # Implicit output

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Encode the column cipher
Given a string to encode, and a number of columns (the key), encode the string as follows:
I will be using the example Hello, world! and the key 3
First, write out the number of columns:
1 2 3

Next, write the text starting from the upper left, one character per column, and when you run out of columns, go to the next line.
1 2 3
H e l
l o ,
  w o
r l d
!

Now, to get your encoded text, read the text starting from the top left corner, but this time, first read one column, and then the next, and so on. If there is not a character in the slot, put a space.
Hl r!eowl l,od

Note that here, there is a trailing space.
This is your encoded text.
Another test case is Programming Puzzles and Code Golf SE with key 5:
1 2 3 4 5
P r o g r
a m m i n
g   P u z
z l e s
a n d   C
o d e   G
o l f   S
E

The encoded text is PagzaooErm lndl omPedef gius    rnz CGS.
More test cases
"abcdefghijklmnopqrstuvwxyz", 2 -> "acegikmoqsuwybdfhjlnprtvxz"
"codegolf.stackexchange.com", 4 -> "cg.ccgoooskhemdltea. efaxnc "
"Pen Pineapple Apple Pen!!!", 7 -> "PeAeeapnnpp! pl!Ple!ie  n P "
"1,1,2,3,5,8,13,21,34,55,89", 10 -> "18,,,5115,3,2,8,2931 ,, 53 ,4 "

Remember, this is code-golf, so the code with the fewest bytes wins.

Oops, nope, my fault

Related.

@TimmyD Fixed..

I think you should include a few more test cases to verify that padding is handled correctly.

Your new test case follows exactly the same pattern as the old one. A potential edge case occurs when the string's length is a multiple of the key, e.g., Programming Puzzles and Code Golf, 3.

MATL, 4 bytes
e!1e

Try it online!
This is about as straightforward as possible. e is a builtin that reshapes a matrix into n rows. So we read in input1 as a string, and shape into a matrix with input2 rows:
Hl r!
eowl
l,od

Then, we transpose it to get this:
Hel
lo,
 wo
rld
!

After that, we just call 1e to reshape it into a single row, and display it as a string.
As you can see in this sample program, the "reshape" function conveniently adds as many zeroes as necessary for the matrix to be a perfect rectangle. When displaying as a string, MATL treats '0's as spaces, so this automatically fills in the necessary number of spaces for no extra work.

and the code is almost palindromic! :-)

@LuisMendo Oh, It's definitely a palindrome, it's just that my shift key is broken. :P

Jelly, 3 bytes
sz⁶

TryItOnline!
How?
sz⁶ - Main link: string, columns
s   - split string (a list of characters) into chunks of length column
 z  - transpose the resulting list of lists with filler
  ⁶ - literal ' '
    - implicit print

This doesn't include the filler spaces.

I just didn't include the trailing space when I typed the argument for the example.

The input doesn't have a trailing space. You're required to insert extra spaces as padding when the string length isn't a multiple of the number.

Is it correct now?

Yup, looks good.

Pyth - 5 bytes
s.tcF

Try it online here.

+1 Much better than my ugly solution. :)

@boboquack don't worry, pyth has its own "idiomatic style" that's actually quite a bit different from python, and you'll learn it as you write more programs (and start to remember the command list :P). Good luck!

Python 2, 46 bytes
lambda s,n:(s[0]+(s[1:]+-len(s)%n*' ')*n)[::n]

The idea is to take the input string, copy it n times with the first character from removed, then takes every n'th character.
Let's look for example at s="abcdef", n=3, where the length is a multiple of n:
abcdefbcdefbcdef
^  ^  ^  ^  ^  ^
a  d  b  e  c  f

The first cycle through the string takes every nth character from the first one. Then, each subsequent cycle shifts one index to the right because the first character is skipped. To ensure that the length is a multiple of n, the initial string is padded with spaces.

PHP, 85 Bytes
for(;$i<$x=$argv[2];$i++)for($j=0;$j<strlen($t=$argv[1])/$x;)echo$t[$i+$j++*$x]??" ";

PHP, 90 Bytes
for(;$i<$x=$argv[2];$i++)foreach(array_chunk(str_split($argv[1]),$x)as$a)echo$a[+$i]??" ";

Ruby, 78 67 65 bytes
->s,k{s.gsub!(/(.)(.{,#{k-=1}})/){$><<$1
$2.ljust k}while s=~/./}

See it on eval.in: https://eval.in/668412
Ungolfed
->s,k{
  s.gsub!(/(.)(.{,#{ k -= 1 }})/) {
    $> << $1
    $2.ljust k
  } while s =~ /./
}

Perl, 61 bytes
54 bytes of codes and -F -pi flags.
for$l(1..$^I){$\.=$F[$^I*$_+~-$l]//$"for 0..$#F/$^I}}{

Takes the input string without final newline, and the key should be placed after -i flag :
$ echo -n "Hello, World!" | perl -F -pi3 -E 'for$l(1..$^I){$\.=$F[$^I*$_+~-$l]//$"for 0..$#F/$^I}}{'
Hl r!eoWl l,od

Python 2, 58 bytes
lambda s,n:`sum(zip(*zip(*n*[iter(s+' '*~-n)])),())`[2::5]

Test it on Ideone.

I really like def f(s,n):t=[*s,' '];del t[print(end=s[::n]):f(''.join(t),n-1):n], but it's too long...

JavaScript (ES6), 84 bytes
It's a recursive solution.
f=(s,k,i=0,r=Math.ceil(s.length/k),c=s[i%r*k+i/r|0])=>k*r==i?'':(c?c:' ')+f(s,k,++i)

R, 92 81 bytes
function(x,n)cat(t(matrix(c(el(strsplit(x,"")),rep(" ",-nchar(x)%%n)),n)),sep="")

Try it on R-fiddle
This turned out to be a bit of a headache because R automatically recycles the input vector when the rows or column specified in the matrix creation is not a multiple of the length of the input. Therefore we have to pad the vector with -nchar(x)%%n spaces before passing it to the matrix function.
The last step is just transposing the matrix and printing it.

What's the purpose of l=nchar(x)?  You don't seem to be using l anywhere. Function el is quite the discovery though, +1.

@plannapus I honestly don't know why I put it there. I believe it is a remnant of how I first calculated the number of times the blank space was being repeated. Good catch though.

Japt, 15 bytes
U+SpV f'.pV)y q

Test it online!
Japt has an "all subsections of length N" built-in, but neither a "all non-overlapping subsections" nor "every Nth char". Suddenly, there is a gaping hole in my life...
Explanation
U+SpV            // Take U concatenated with V spaces.
      f'.pV)     // Take every substring of 3 chars.
            y    // Transpose the resulting array.
              q  // Join on the empty string.
                 // Implicit: output last expression

Mathematica, 43 40 bytes
Thanks to miles for saving three bytes!
Join@@Thread@Partition[##,#2,{1,1}," "]&

Unnamed function taking two arguments, an array of characters and an integer; returns an array of characters.
Most of the heavy lifting is done by the Thread function, which (in this context) exchanges rows and columns. Partition needs to be called with a couple of useless arguments so that it will pad with the fifth argument " ".

You can use Thread also instead of Transpose Join@@Thread@Partition[##,#2,1," "]&

whoa. I get it now!

Pyth, 40 bytes
=Zw=+Z*d+Q-*Q/lZQlZV*QlZIq%%NlZQ/NlZp@ZN

Test it here
Probably the ugliest Pyth code ever, but this is my first attempt at Pyth.
=Zw=+Z*d+Q-*Q/lZQlZV*QlZIq%%NlZQ/NlZp@ZN
         Q                               Set Q to eval(input())
=Zw                                      Initialises Z to next input string
              lZ                         Gets the length of Z
             /lZQ                        Integer divides lZ by Q
           *Q/lZQ                        Multiplies that result by Q
          -*Q/lZQlZ                      Subtracts the length of Z from that
        +Q-*Q/lZQlZ                      Adds Q to that
                                         (This is how many spaces to pad)
      *d+Q-*Q/lZQlZ                      Gets that many spaces (d is set to ' ')
   =+Z*d+Q-*Q/lZQlZ                      Appends that to Z
                    *QlZ                 Multiplies Q by lZ
                   V*QlZ                 Does a for loop for integers in that range, on N
                           %NlZ          Gets N modulo lZ
                          %%NlZQ         Gets that modulo Q
                                         This is the column of the letter at index N mod Q
                                /NlZ     Gets the column that is being printed
                        Iq%%NlZQ/NlZ     If they are equal...
                                    p@ZN Print the index of N into Z without a newline
                                         (This is implicitly modulo the length of Z)

If anyone has tips to improve my golfing, please leave a comment!

Don't worry, my first try with Pyth was just as long :) The number of spaces to pad is equal to (-len(Z))%Q, so you can replace +Q-*Q/lZQlZ with %_lZQ. (Alternatively, you could rearrange +Q-*Q/lZQlZ to +-*/lZQQlZQ. It's not shorter, but +-*/ looks cool ;) )

Actually, 12 bytes
Golfing suggestions welcome, especially if you can figure out a golfier way to pad spaces. Try it online!
;' *(q╪dX┬ΣΣ

Ungolfing
      Implicit input s, then n.
;     Duplicate n. Stack: n, n, s
' *   Push n spaces.
(q    Rotate s to TOS and append the spaces to the end of s.
╪     Split s into n-length substrings.
dX    Dequeue and discard any extra spaces that remain after chunking.
      This works even when we didn't need to add spaces in the first place.
┬     Transpose the remaining substrings. This returns a list of lists of chars.
Σ     Sum the transposed substrings into one list of chars.
Σ     Sum the list of chars into one string.
      Implicit return.

Another 12-byte version
In this version, the order of the inputs is reversed, but this can be changed if that isn't allowed. Golfing suggestions welcome. Try it online!
│l±%' *o╪┬ΣΣ

Ungolfing
      Implicit input n first, then s.
│     Duplicate stack. Stack: s, n, s, n
l±    Push -len(s).
%     Push -len(s)%n, which gets the number of spaces we need to pad with. Call this m.
' *   Push m spaces to the stack.
o     Append the spaces to the end of s.
╪     Split s into n-length substrings.
┬     Transpose these substrings. This returns a list of lists of chars.
Σ     Sum the transposed substrings into one list of chars.
Σ     Sum the list of chars into one string.
      Implicit return.

Pyke, 10 bytes
k=.,Rc.,ss

Try it here!

C#, 161 bytes
I am so sorry.
(s,i)=>String.Join("",Enumerable.Range(0,i).SelectMany(x=>Enumerable.Range(0,s.Length/i+1).Select(n=>(n*3+x)).Where(m=>m<s.Length).Select(o=>s.Substring(o,1))));

Perl, 87 bytes
($a,$b)=@ARGV;for$c(1..$a){for(0..(length$a)/$b){$e.=substr($a,$b*$_+$f,1)}$f++;}say$e;

Accepts two arguments as parameters and
Usage:
perl -M5.010 encol.pl "Hello, World!" 3
Hl r!eoWll,od

@Dada Why don't you post it as your own answer?

 Ruby, 89 bytes
->s,i{t="";i.times{|n|s.ljust(i*(s.size*1.0/i).ceil).scan(/#{?.*i}/).each{|j|t<<j[n]}};t}

Terrible score, tips appreciated.

Use size instead of length for one byte.

@Jordan Wouldn't it be two?

GolfSharp, 82 bytes
(s,i)=>r(0,i).m(x=>r(0,s.L()/i+1).s(n=>(n*3+x)).w(m=>m<s.L()).s(o=>s.R(o,1))).j();

Groovy, 90 Bytes
{s,n->(s.padRight((int)(s.size()/n+1)*n) as List).collate(n).transpose().flatten().join()}

Pad the input by the ceiling of the size divided into n chunks.
Get the padded string as a list of characters.
Collate into n chunks and transpose.
({s,n->(s.padRight((int)(s.size()/n+1)*n) as List).collate(n).transpose().flatten().join()})("Programming Puzzles and Code Golf SE",5)

Results in:
PagzaooErm lndl omPedef gius    rnz CGS

Python 3, 48 bytes
lambda c,k:''.join([c[i:-1:k]for i in range(k)])

Powershell, 57 bytes
param($s,$n)$r=,''*$n
$s|% t*y|%{$r[$i++%$n]+=$_}
-join$r

Test script:
$f = {

param($s,$n)$r=,''*$n
$s|% t*y|%{$r[$i++%$n]+=$_}
-join$r

}

@(
    ,("abcdefghijklmnopqrstuvwxyz", 2  , "acegikmoqsuwybdfhjlnprtvxz")
    ,("codegolf.stackexchange.com", 4  , "cg.ccgoooskhemdltea.efaxnc")
    ,("Pen Pineapple Apple Pen!!!", 7  , "PeAeeapnnpp! pl!Ple!ie n P")
    ,("1,1,2,3,5,8,13,21,34,55,89", 10 , "18,,,5115,3,2,8,2931,,53,4")
) | % {
    $s,$n,$expected = $_
    $result = &$f $s $n
    "$($result-eq$expected): $result"
}

Output:
True: acegikmoqsuwybdfhjlnprtvxz
True: cg.ccgoooskhemdltea.efaxnc
True: PeAeeapnnpp! pl!Ple!ie n P
True: 18,,,5115,3,2,8,2931,,53,4

SINCLAIR ZX81/TIMEX TS-1000/1500 BASIC, 134 tokenized BASIC bytes
 1 INPUT A$
 2 INPUT A
 3 LET C=-SGN PI
 4 FOR I=SGN PI TO A
 5 PRINT I;
 6 NEXT I
 7 PRINT
 8 FOR I=SGN PI TO LEN A$
 9 LET C=C+SGN PI
10 IF C=A THEN LET C=NOT PI
11 IF NOT C AND I>SGN PI THEN PRINT
12 PRINT A$(I);
13 NEXT I

The first parameter A$ is the string value that you want to cipher, and the second A is the number of columns that you want to cipher to. The variable C is used to add in a new line after A characters.
Lines 4 to 6 inclusive print out the column numbers at the top of the screen area.
Line 7 adds a new line ("\r\n" equivalent).
Lines 8 - 13 will then print out each character of A$.
This programme does not require a RAM expansion to work.

K (oK), 27 bytes
Solution:
{,/+(0N;y)#(y*-_-(#x)%y)$x}

Try it online!
Explanation:
{,/+(0N;y)#(y*-_-(#x)%y)$x} / the solution
{                         } / lambda taking implicit x and y
                        $x  / pad x
           (           )    / do this together
                     %y     / divide by y
                 (  )       / do this together
                  #x        / count (#) length of x
                -           / negate \
               _            / floor   | ceiling
              -             / negate /
            y*              / multiply by y
          #                 / reshape
    (0N;y)                  / null by y grid
   +                        / transpose
 ,/                         / flatten

05AB1E (legacy), 3 bytes
ôζJ

The Python legacy version is used instead of the Elixir rewrite, because the new version doesn't implicitly convert strings to characters when using zip, which the old version did.
Try it online or verify all test cases.
Explanation:
ô      # Split the (implicit) input-String into chunks of size (implicit) input-integer
       #  i.e. "Hello, world!" and 3 → ['Hel','lo,',' wo','rld','!']
 ζ     # Zip, swapping rows and columns (with space filler by default)
       #  i.e. ['Hel','lo,',' wo','rld','!'] → ['Hl r!','eowl ','l,od ']
  J    # Join the list of strings together (and output implicitly)
       #  i.e. ['Hl r!','eowl ','l,od '] → 'Hl r!eowl l,od '

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
What's the most popular question right now?
Your task is to print the titles of the questions with the five highest scores (upvotes minus downvotes) here on CodeGolf.SE, while skipping over any closed, locked and on-hold questions.
Currently these are:
Produce the number 2014 without any numbers in your source code
Showcase your language one vote at a time
American Gothic in the palette of Mona Lisa: Rearrange the pixels
Images with all colors
Build a Compiler Bomb

Remember, this is code-golf, so the code with the smallest number of bytes wins.

Nitpick: "most popular right now" would better describe what's at the top of the "hot" list ;)

Would using a URL shortener be cheating?

@Artyer Yes. It violates a standard loophole.

JavaScript + JQuery, 178 bytes
Quite a simple approach that makes the StackExchange API do all the work.

$.ajax('//api.stackexchange.com/search/advanced?sort=votes&closed=False&wiki=False&notice=False&pagesize=5&site=codegolf').pipe(x=>x.items.map(x=>document.write(x.title+'
')))

a=x=>x.items.map(x=>document.write(x.title+'
'))
document.write('StackExchange Site: <input value="codegolf"> <button onclick="$.ajax({success:x=>{try{document.getElementById('pre').innerHTML=x.items.map(x=>x.title).join('\n')+'\n\nQueries left: ' + x.quota_remaining}catch(e){try{document.getElementById('pre').textContent='Queries left: ' + (x.quota_remaining || 'Error')}catch(e){document.getElementById('pre').textContent='Error'}}},url:'//api.stackexchange.com/search/advanced?sort='+document.getElementById('s').value+'&closed=False&wiki=False&notice=False&pagesize=5&site=' + this.previousElementSibling.value})">Go</button> Sort by: <select id='s'><option value="activity">Active</option><option value="votes" selected="selected">Score</option><option value="creation">New</option></select>

Some caveats while answering this question:

StackExchange API always trys to returns gzipped data. In JS, the browser un-gzips for you.
The API only seems to be able to return the top 100 at maximum, so if you were to filter out the closed questions programatically, you must assume that less than 96 of the top 100 questions are closed, which you can't so you have to do everything in the APIs query.
The things in the API are HTML encoded, so you must also decode those. In JS, I let the browser decode it, but in something like Python, you must employ an external library, or else hard-code the dozens of entities.

That said, here is my Python solution that has to jump all of those hoops:
Python 3, 259 bytes
import urllib.request as r,gzip,html,json
for i in json.loads(gzip.decompress(r.urlopen('http://api.stackexchange.com/search/advanced?sort=votes&closed=False&wiki=False&notice=False&pagesize=5&site=codegolf').read()))['items']:print(html.unescape(i['title']))

Bash + curl + gunzip + recode + jq, 165 bytes

(Newline for clarity)
curl "api.stackexchange.com/search/advanced?sort=votes&closed=False&wiki=False&notice=False&pagesize=5&site=codegolf"
|gunzip|jq -r ".items[].title"|recode html:ascii

Or if you don't want any output on stderr for 4 more bytes :
curl -s "api.stackexchange.com/search/advanced?sort=votes&closed=False&wiki=False&notice=False&pagesize=5&site=codegolf"
|gunzip|jq -r ".items[].title"|recode html..ascii

I thought a bash solution using @Artyer's url would be shorter, turns out it's not that much.
Problems that make it longer :

The stackexchange API responds with compressed data. Using curl's --compressed flag, gzip -d or gunzip solve that, gunzip being the shortest
We need to translate HTML entities
jq outputs JSON data, where strings are enclosed in quotes. Using -r makes it output raw data.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Generate a one-path maze
Given an odd integer N (5 <= N <= 51), generate a maze with side length N that follows the following requirements:
The maze must be composed of the characters  | - and +. It must use the | character as a vertical wall, the - character as a horizontal wall, and if that wall turns, the character + should be used.
The width of the path must be one character.
The maze must turn at least four times.
The maze must have outer walls, that break at two points: the start and the end.
The maze must consist of one non-breaking path, from the start to the end.
For example, the following is a valid maze: (N = 5)
+---+
|   |
| | |
  |
--+--

And for N = 7:
--+---+
  |   |
| | | |
| | | |
| | | |
|   |
+---+--

Remember, this is code-golf, so the code with the fewest number of bytes wins.

It's not a maze, it's a labyrinth http://english.stackexchange.com/a/144103/199361

@edc65 Actually, its nighter.

I'm not clear on "The maze must consist of one non-breaking path, from the start to the end." Does this mean that there is only one-path and it's from start to end, or that the number of paths from start to end is 1? Can there be other paths with dead ends? Separate loops?

Odd integer should be <50, <=49

@edc65 I assume OP means neither.

@edc65 Welcome to [tag:labyrinth]!

Do both the width AND height have to be size N? I could comply to all your specified requirements, but only have either one size N and the other not.

@KevinCruijssen Yes.

Jelly, 36 35 34 33 32 bytes
2*×5H_2Bị⁾ |
_3”-ẋ”+;;Çsẋ2U3¦ṁµY

TryItOnline!
Builds a nighter™ the other way around to the examples like:
+---- |
|     |
| ----+
|     |
+---- |
|     |
| ----+

How?
2*×5H_2Bị⁾ | - Link 1, pipes & spaces: n      e.g. 7
2*           - 2 raised to the nth power      e.g. 128
  ×5         - multiply by 5                  e.g. 640
    H        - halve                          e.g. 320
     _2      - subtract 2                     e.g. 318
       B     - convert to binary              e.g. [1,0,0,1,1,1,1,1,0]
        ị    - index into (1-based)
         ⁾ | - char list " |"                 e.g. " ||     |"

_3”-ẋ”+;;Çsẋ2U3¦ṁµY - Main link: n            e.g. 7
_3                  - n - 3                   e.g. 4
  ”-                - char list "-"
    ẋ               - repeat                  e.g. "----"
     ”+             - char list "+"
       ;            - concatenate             e.g. "+----"
         Ç          - call last link (1) as a monad
        ;           - concatenate             e.g. "+---- ||     |""
          s         - split into chunks of n  e.g. ["+---- |","|     |"]
           ẋ2       - repeat 2 times          e.g. ["+---- |",
                                                    "|     |",
                                              +-->  "+---- |",
                                              |     "|     |"]
              3¦    - apply to index 3:       |
             U      -    upend                +---  "| ----+"
                ṁ   - mould like n (i.e. repeat to fill)
                 µ  - monadic chain separation
                  Y - join with line feeds

(each byte saved involved fairly non-trivial changes, see the edit history if you're interested, although I just noticed that Link 1 is the same byte count as the more conventional repeat and join: _2⁶ẋ“ ||“|”j)

JavaScript (ES6), 86 92 116
Almost a kolmogorv-complexity challenge ...
With a little lateral thinking (inspired by @Neil's answer), it can be very shorter. Just turn 90°

n=>`|${s=' '[r='repeat'](n-2)}|
| ${h='-'[r](n-3)}+
|${s}|
+${h} |
`[r](n).slice(n*~n)

Test

f=
n=>`|${s=' '[r='repeat'](n-2)}|
| ${h='-'[r](n-3)}+
|${s}|
+${h} |
`[r](n).slice(n*~n)

function update() {
  var i=+I.value
  O.textContent=i&1? f(i): 'even'
}

update()
<input id=I value=7 min=5 max=49 step=2 type=number oninput="update()">

@Neil wow every day I learn something new. Thanks

Amazing! I count 86 bytes, btw

@ETHproductions right. Thanks

Batch, 216 bytes
@echo off
set s=
for /l %%i in (4,1,%1)do call set s=-%%s%%
set b= %s:-= %
set r=! %s%+
set s=+%s% !
call:e
for /l %%i in (5,2,%1)do call:l
:l
echo ^|%b%^|
set t=%s%
set s=%r%
set r=%t%
:e
echo %s:!=^|%

|s are awkward in Batch so I reflected rotated the examples instead.

Do you mean rotate 90°? I tried it and saved a lot in JS. Thanks again

@edc65 I was originally going for a reflection, but you're right in that I ended up with a rotation instead.

PHP, 99 Bytes
up to down gates
for($s=str_pad("\n| ",$c=$argv[1],"-")."+\n";$i++<$c;)echo$i%2?$s=strrev($s):str_pad("|",$c-1)."|";

PHP, 157 Bytes
left right gates
<?=($p=str_pad)($n="\n",$c=1+$argv[1],"+---").$p($n,$c-1,"|   ")." #|"[$c%4].str_repeat($p($n,$c,"| "),$c-5).$p($n,$c-1,"  | ")."|# "[$c%4].$p($n,$c,"--+-");

@Titus Thank you for minialize the bytes

save 3 bytes by assigning `$n="\n"

$p("",$c*($c-4),...) instead of str_repeat(...,$c-4) (-2)

... and 3 more bytes with $p($n,$c-1,"  | ") instead of $p("\n ",$c-1," |  ")

unnecessary parens at ($c)%4 (-2), remove $g from the code (-1)

up-to-down-version; unnecessary 3rd parameter for str_pad (-4), $c=$argv[1]-1 instead of ($c=$argv[1])-1, <=$c instead of <$c and $c instead of $c-1 (-3)

... and, if a leading newline is accepted: undo the other tip, replace ($c=$argv[1])-1 with $c=$argv[1], "| " with "\n| ", "+" with "+\n" and remove ,"\n" (-2)

@Titus left right Thank You! the space after the new line is necessary for the gate line and I could it not change and replace str_repeat with str_pad I have count the same bytes

Yes, but you can move the space to the beginning of the padding string and cut one space from the end.

@Titus for the up an down version you have seen that I am use strrev? And in my opinion that can not work with your suggestion with the leading new lines

My new $s has a leading and a trailing newline; that´s why you don´t need a newline for the other string anymore.

@Titus okay that  have not realize in the moment

Use real newline instead of \n. It will save you one byte twice.

JavaScript (ES6), 87 bytes
A recursive function. Outputs a few trailing spaces.
f=(n,w=n,s=' -'[n&1].repeat(w-3),c='|+'[n&1])=>n?`
`+(n&2?c+s+' |':'| '+s+c)+f(n-1,w):s

Test

f=(n,w=n,s=' -'[n&1].repeat(w-3),c='|+'[n&1])=>n?`
`+(n&2?c+s+' |':'| '+s+c)+f(n-1,w):s

console.log(f(9));

Oh wow, I just tried recursion and ended up 9 bytes longer. Well done :-)

Ruby 72 or 69 bytes
Lambda function. As shown, returns a newline-separated string. Delete the *$/ to return an array of strings.
->n{(1..n).map{|i|"|%s |+%s || %s|| %s+"[i%4*5,5]%(" -"[i%2]*(n-3))}*$/}

Draws a maze rotated 90 degrees from the examples. For each line, a format string is selected (for example +%s | for the 1st line (there is no zeroth line) and the %s is substituted with an appopriate number of - or spaces using the % operator (equivalent to sprintf, but shorter.)

Java 7, 228 bytes
String c(int n){String a="+x |",b="|y|\n",x,y,r=x=y="";int i=0;for(;i++<n-2;){x+=i>1?"-":"";y+=" ";}a=a.replace("x",x);b=b.replace("y",y);for(i=0;i<n;i++)r+=i%4<1?a+"\n":(i-2)%4==0?new StringBuffer(a).reverse()+"\n":b;return r;}

Used a similar vertical output as @JonathanAllan's Jelly answer.
Ungolfed & test code:
Try it here.
class M{
  static String c(int n){
    String a = "+x |",
           b = "|y|\n",
           x = "",
           y = "",
           r = "";
    int i = 0;
    for (; i++ < n-2;){
      x += i > 1
            ? "-"
            : "";
      y += " ";
    }
    a = a.replace("x", x);
    b = b.replace("y", y);
    for(i = 0; i < n; i++){
      r += i % 4 < 1
            ? a+"\n"
            : (i-2) % 4 == 0
               ? new StringBuffer(a).reverse()+"\n"
               : b;
    }
    return r;
  }

  public static void main(String[] a){
    System.out.println(c(7));
    System.out.println();
    System.out.println(c(25));
  }
}

Output:
+---- |
|     |
| ----+
|     |
+---- |
|     |
| ----+

+---------------------- |
|                       |
| ----------------------+
|                       |
+---------------------- |
|                       |
| ----------------------+
|                       |
+---------------------- |
|                       |
| ----------------------+
|                       |
+---------------------- |
|                       |
| ----------------------+
|                       |
+---------------------- |
|                       |
| ----------------------+
|                       |
+---------------------- |
|                       |
| ----------------------+
|                       |
+---------------------- |

excuse, but Given an odd integer N (5 <= N <= 51), generate a maze with side length N. You seem to have a different top and bottom side length for yours...

@DestructibleWatermelon I read past that. My code still complied to all rules/requirements though. Ah well, I've roll-backed to my original answer which used the same width as height.

Python 2, 89 bytes
def f(n):x='+'+'-'*(n-3)+' |';y='|'+' '*(n-2)+'|';print'\n'.join(([x,y,x[::-1],y]*n)[:n])

repl.it
Builds an internal wall, x, like '+---- |' and an internal corridor, y, like '|     |'
Then builds a list of [x,y,x[::-1],y] (x[::-1] is a reverse of x)
Then repeats that list n times (as a single list), with *n, and truncates it to the first n entries, with (...)[:n], joins the list with line feeds, with '\n'.join(...), and prints the result.

Racket 187 bytes
Using display pattern by @JonathanAllan
(let*((u "+---- |")(v "|     |")(sr(λ(s)(list->string(reverse(string->list s)))))(g #t)(d displayln)
(p(λ()(d(if g u(sr u)))(set! g(if g #f #t)))))(for((i(ceiling(/ n 2))))(p)(d v))(p))

Ungolfed:
(define (f n)
  (let* ((sr (lambda(s)
               (list->string
                (reverse
                 (string->list s)))))
         (u "+---- |")
         (v "|     |")
         (g #t)
         (d displayln)
         (p (lambda()
              (d (if g u (sr u)))
              (set! g (if g #f #t)))))
    (for ((i (ceiling (/ n 2))))
      (p)
      (d v))
    (p)))

Testing:
(f 10)

Output:
+---- |
|     |
| ----+
|     |
+---- |
|     |
| ----+
|     |
+---- |
|     |
| ----+

T-SQL, 123/79 bytes
Golfed:
DECLARE @i INT=7

,@ INT=0z:PRINT
STUFF(CHOOSE(@%4+1,'+- |','|  |','| -+','|  |'),3,0,REPLICATE(IIF(@%2=0,'-',' '),@i))SET
@+=1IF @<@i GOTO z

Ungolfed:
DECLARE @i INT = 9

DECLARE @i INT=7

,@ INT=0
z:
  PRINT
    STUFF(CHOOSE(@%4+1,'+- |','|  |','| -+','|  |'),3,0,
      REPLICATE(IIF(@%2=0,'-',' '),@i))
  SET @+=1
IF @<@i GOTO z

If you cheat and only make a narrow labyrinth the script can be golfed down to 79 bytes:
Golfed:
DECLARE @i INT = 9

,@ INT=0z:PRINT CHOOSE(@%4+1,'+- |','|  |','| -+','|  |')SET @+=1IF @<@i GOTO z

Ungolfed:
DECLARE @i INT = 9

,@ INT=0
z:
  PRINT CHOOSE(@%4+1,'+- |','|  |','| -+','|  |')
  SET @+=1
IF @<@i GOTO z

Fiddle for the long answer

GNU sed 140 bytes
Includes +1 for -r
s/1{5}//
h
s/^/+---+\n|   |\n| | |\n  |  \n--+--/
/1/!b
:w
s/^..(..)[^$]*/\1&/gm
s/11//
/1/bw
G
:h
s/\n[^\n]*\n([^\n]*\n)/&\1/
s/1//
/1/bh

Try it Online!
Takes input in unary (see this consensus).
Basically it inserts the size 5 maze, then appends the 2nd and 3rd character of each line to the beginning as many times as needed. Then duplicates the 3rd line (alternating | and ) as many times as needed.
The only interesting thing that I used is the m option on line 6 which allows ^ and $ to match respectively (in addition to the normal behavior) the empty string after a newline, and the empty string before a newline.

JavaScript (ES6), 96 bytes
f=(n,w=n-3)=>(h="-".repeat(w),n&2?`+${h} |`:`| ${h}+`)+(n>1?`
| ${" ".repeat(w)}|
`+f(n-2,w):"")

I was hoping recursion would turn out to be the shortest route, and apparently it is...


text:
Positional Bathroom Etiquette
Background
Bathroom Etiquette, when pertaining to the available urinals, states that the next urinal to be filled in should be the one that minimizes the total discomfort. The total discomfort equation is given by the following set of equations:

dist(x,y) = linear distance between person x and person y in Urinal Units
discomfort(x) = sum(1/(dist(x,y)*dist(x,y))) for all persons y excluding person x
total_Discomfort = sum(discomfort(x)) for all x

A more in depth paper dealing with a similar (not the exact same) problem can be found here: (Thanks to @Lembik for alerting me to this amazing whitepaper!)

Input/Output
Given an input of a empty and full urinals, output the resulting set of urinals with the addition of one person. If there is a tie for a position the urinals should fill in left to right. The output should be in the same format as the input.

If given a case with full urinals, return the input.
The input will always have at least one urinal defined.

Test Cases

INPUT     -> OUTPUT
1000001   -> 1001001
101010101 -> 111010101
100       -> 101
00000     -> 10000
1111111   -> 1111111
0100      -> 0101
101000    -> 101001

Rules
This is code-golf, so shortest code in bytes wins. Standard loop-holes are forbidden.

Related problem: http://codegolf.stackexchange.com/questions/47952/the-urinal-protocol

It is recommended to wait about a week before accepting an answer. Accepting in less than a day might decrease the amount of answers your challenge receives.

I'd suggest adding 0100 and 101000 in the test cases (some regex-based approach work on the actual test cases but won't work on those ones which should still be handled)

also related: http://codegolf.stackexchange.com/questions/94074/checkmate-aka-the-urinal-problem

@TheBitByte How is it offensive? It's a pretty accurate description of how men choose urinals in a bathroom.

@TheBitByte Good thing no bodily fluids have been mentioned. "Urinal" is not offensive in any way. Deal with it.

Jelly, 13 12 bytes
J_þTİ²SiṂ$Ṭo

Try it online! or Verify all test cases.
Explanation
J_þTİ²SiṂ$Ṭo  Input: boolean array A
J             Indices, returns [1, 2, ..., len(A)]
   T          Truthy indices, returns the indices which have a truthy value
 _þ           Form the subtraction (_) table (þ) between them
    İ         Inverse, find the reciprocal of each
     ²        Square each
      S       Sum the sublists column-wise
         $    Monadic chain
        Ṃ       Minimum
       i        Find the first index of that
          Ṭ   Untruth indices, returns a boolean array with 1's at those indices
           o  Logical OR between that and A, and return

MATL, 19 18 17 bytes
lyf!Gn:-H_^Xs&X<(

Try it online! Or verify all test cases (slightly modified code).
Explanation
It suffices to compute the distance from each potential new position to the already occupied ones. The remaining distances are do not depend on the potential new position, and so constitute a constant term, which can be ignored.
Let's take input [1 0 0 0 0 0 1] as an example.
l      % Push 1
       % STACK: 1
y      % Take input implicitly. Duplicate from below
       % STACK: [1 0 0 0 0 0 1], 1, [1 0 0 0 0 0 1]
f!     % Indices of nonzero elements, as a column array
       % STACK: [1 0 0 0 0 0 1], 1, [1 7]
Gn:    % Push [1 2 ... n], where n is input size (array of possible positions)
       % STACK: [1 0 0 0 0 0 1], 1, [1; 7], [1 2 3 4 5 6 7]
-      % Matrix with all pairs of differences
       % STACK: [1 0 0 0 0 0 1], 1, [1; 7], [0 -1 -2 -3 -4 -5 -6;
                                             6  5  4  3  2  1  0]
H_^    % Raise each entry to -2
       % STACK: [1 0 0 0 0 0 1], 1, [   Inf 1.0000 0.2500 0.1111 0.0625 0.0400 0.0278;
                                     0.0278 0.0400 0.0625 0.1111 0.2500 1.0000    Inf]
Xs     % Sum of each column
       % STACK: [1 0 0 0 0 0 1], 1, [Inf 1.04 0.3125 0.2222 0.3125 1.04 Inf]
&X<    % Index of minimum. Takes the first if there is a tie
       % STACK: [1 0 0 0 0 0 1], 1, 4
(      % Assign: write 1 at the position of the minimizer
       % STACK: [1 0 0 1 0 0 1]
       % Implicitly display

JavaScript (ES6), 89 bytes
a=>a[a.map((e,i)=>!e&&(t=0,a.map((e,j)=>t+=(j-=i)&&e/j/j),t<m&&(m=t,k=i)),k=0,m=1/0),k]=1

Outputs by modifying the input array.

R, 83 76 67 bytes
Just realized that I can save several bytes by not bothering to check if the candidate urinals are empty. Non-empty urinals will always return an Inf discomfort value, so they're excluded in the course of the calculation. Also, just using direct indexing rather than replace, so it's shorter but less elegant.
x=scan()
x[which.min(rowSums(outer(seq(x),which(!!x),`-`)^-2))]=1
x

Explanation
x=scan()

We read the current state from stdin and call it x. We assume that the input is a sequence of 1s and 0s separated by spaces or newlines. For the purposes of the explanation, let's say we input 1 0 0 0 0 0 1.
x[which.min(rowSums(outer(seq(x),which(!!x),`-`)^-2))]=1

We replace a value of x at a particular index with 1. Everything between the [ ] is figuring out what the best index is.
Since the existing urinals are immutable, we don't need to consider the distances between them. We only need to consider the distances between the occupied urinals and the possible new one. So we determine the indices of the occupied urinals. We use which, a function to return the indices of a logical vector which are TRUE. All numbers in R, when coerced to type logical, are TRUE if nonzero and FALSE if zero. Simply doing which(x) will result in a type error, argument to 'which' is not logical, as x is a numeric vector. We therefore have to coerce it to logical. ! is R's logical negation function, which automatically coerces to logical. Applying it twice, !!x, yields a vector of TRUE and FALSE indicating which urinals are occupied. (Alternative byte-equivalent coercions to logical involve the logical operators & and | and the builtins T and F, e.g. F|x or T&x and so on. !!x looks more exclamatory so we'll use that.)
                                 which(!!x)

This is paired with seq(x), which returns the integer sequence from 1 to the length of x, i.e. all urinal locations (and thus all possible locations to consider).
                          seq(x)

Now we have the indices of our occupied urinals: 1 7 and our empty urinals 1 2 3 4 5 6 7. We pass `-`, the subtraction function, to the outer function to get the "outer subtraction", which is the following matrix of distances between all urinals and the occupied urinals:

[,1] [,2]
[1,]    0   -6
[2,]    1   -5
[3,]    2   -4
[4,]    3   -3
[5,]    4   -2
[6,]    5   -1
[7,]    6    0

                    outer(seq(x),which(!!x),`-`)

We raise this to the -2th power. (For those who are a little lost, in the OP, "discomfort" is defined as 1 / (distance(x, y) * distance(x, y)), which simplifies to 1/d(x,y)^2, i.e. d(x,y)^-2.)
                    outer(seq(x),which(!!x),`-`)^-2

Take the sum of each row in the matrix.
            rowSums(outer(seq(x),which(!!x),`-`)^-2)

Get the index of the smallest value, i.e. the optimal urinal. In the case of multiple smallest values, the first (i.e. leftmost) one is returned.
  which.min(rowSums(outer(seq(x),which(!!x),`-`)^-2))

And voilà, we have the index of the optimal urinal. We replace the value at this index in x with 1. In the case of 1111 as input, it doesn't matter which one we replace, we'll still have a valid output.
x[which.min(rowSums(outer(seq(x),which(!!x),`-`)^-2))]=1

Return the modified input.
x

Python 3 223 222 165 Bytes
Okay, I know this isn't the prettiest answer out there, and I'm sure it can be golfed down quite a bit, but I was just messing around and seeing what I could do
Shout out to mbomb007 for the tips on whitespace and comparators
Also, I saw my online character counter was taking all the tabs and turning them into spaces, so the count is a lot less than I originally had
def u(a):
 m,r,x=9,0,len(a)
 for i in range(x):
    d=0
    if a[i]<'1':
     for j in range(x):
        if a[j]>'0':d+=float((j-i)**-2)
     if d<m:r=i;m=d
 return a[:r]+'1'+a[r+1:]

Showing revised whitespace:
def u(a):
<sp> m,r,x=9,0,len(a)
<sp> for i in range(x):
<tab> d=0
<tab> if a[i]<'1':
<tab><sp> for j in range(x):
<tab><tab> if a[j]>'0':d+=float((j-i)**-2)
<tab><sp> if d<m:r=i;m=d
<sp> return a[:r]+'1'+a[r+1:]

Original:
def u(a):
    m,r,x=9,0,len(a)
    for i in range(x):
        d=0
        if a[i]!='1':
            for j in range(x):
                if a[j]=='1':d+=float(1/(j-i)**2)
            if d<m:r=i;m=d
    return a[:r]+'1'+a[r+1:]

This expects a string passed to it of 1's and 0's like "10001" and returns a string "10101"
Edit: Changed 1/float((j-i)**2) to float((j-i)**-2)

!='1' can be <'1' and =='1' can be >'0'. Also, consider this tip

Thanks for that whitespace tip. I definitely did not know that. That's awesome!

That whitespace tip only works in Python 2, I think. Maybe early version of Python 3, but idk. You'll have to restrict your answer to Python 2 or some specific version of 3 with it working.

I've got it running in a 3.5.2 shell in IDLE and it's running without an issue, so I think it's alright still

PHP, 135  bytes
$a=explode(1,$argv[1]);$b=0;foreach($a as$c=>$d){$l=strlen($d);if($l>$b){$b=$l;$e=$c;}}if($b)$a[$e][intval($b/2)]=1;echo implode(1,$a);

I'm sure there's a considerably quicker way of doing it, but I've got a fuzzy head and can't think of one!
Old code
The code without minification:
$a=explode(1,$argv[1]);
$b=0;
foreach($a as $c=>$d){
    $l=strlen($d);
    if($l>$b){
        $b=$l;
        $e=$c;
    }
}
if($b){
    $a[$e][intval($b/2)]=1;
}
echo implode(1,$a);

Python 3, 574 471 347 bytes
I'll probably work on this some more, considering the other Python solution is like a fifth of this one :[.
def a(I):
 D,l,r={},len(I),range
 for i in r(l):
  if I[i]<1:
   n,t,n[i]=I[:],[],1
   for j in r(l):
    if n[j]>0:
     q,Q=[],0
     for k in r(l):
      if k!=j and n[k]>0:q.append((k-j,j-k)[k<j])
     for i in q:Q+=1/(i**2)
    t.append(Q)
   T=sum(t)
   if T not in D.keys():D[T]=i
 if len(D)>0:I[D[min(D.keys())]]=1
 print(I)

Well that's much better now that I've learned you can use single spaces.

Python, 165 163 158 147 141 140 139 bytes
def u(p):e=enumerate;a=[(sum((i-j)**-2for j,y in e(p)if"0"<y),i)for i,x in e(p)if"1">x];return a and p[:min(a)[1]]+"1"+p[min(a)[1]+1:] or p

rewrite second line as if"1"*len(p)==p:return p to save a byte

05AB1E, 18 bytes
$āsƶ0Kδ-znD_°+OWkǝ

I/O as a list.
Port of @miles' Jelly answer, so make sure to upvote that answer as well!
Unfortunately, dividing by 0 won't result in INF in 05AB1E like it does in Jelly and MATL, but instead in 0. So 4 bytes (D_°+) are to account for that..
Try it online or verify all test cases.
Explanation:
$                  # Push 1 and the input-list
 ā                 # Push a list in the range [1,length] (without popping the list)
  s                # Swap so the input-list is at the top again
   ƶ               # Multiply each value by its 1-based index
    0K             # Remove all 0s
      δ-           # Pop both lists, and create a subtraction table
        z          # Convert each inner value to 1/value
         n         # Square each inner value
          D        # Duplicate this list
           _       # Check for each inner value whether it equals 0 (1 if 0; 0 otherwise)
            °      # Take 10 to the power this (10 if 0; 1 otherwise)
             +     # Add it to each value at the same positions
              O    # Sum each inner list
               W   # Push the minimum (without popping the list)
                k  # Pop both, and push the (first) (0-based) index of this minimum
                 ǝ # Insert the 1 at this index into the (implicit) input-list
                   # (after which the result is output implicitly)

Scala, 173 bytes
Golfed version. Try it online!
a=>{var(m,r,x,d)=(9d,0,a.size,0d);for(i<-0 to x-1)if(a(i)=='0'){d=0;for(j<-0 to x-1)if(a(j)=='1')d+=math.pow(j-i,-2);if(d<m){r=i;m=d}};a.substring(0,r)+'1'+a.substring(r+1)}

Ungolfed version. Try it online!
object Main {
  def u(a: String): String = {
    var m = 9.0
    var r = 0
    val x = a.length
    for (i <- 0 until x) {
      var d = 0.0
      if (a(i) == '0') {
        for (j <- 0 until x) {
          if (a(j) == '1') {
            d += math.pow(j - i, -2)
          }
        }
        if (d < m) {
          r = i
          m = d
        }
      }
    }
    a.substring(0, r) + '1' + a.substring(r + 1)
  }

  def main(args: Array[String]): Unit = {
    println(u("1000001"))    // should print: 1001001
    println(u("101010101"))  // should print: 111010101
    println(u("100"))        // should print: 101
    println(u("00000"))      // should print: 10000
    println(u("1111111"))    // should print: 1111111
    println(u("0100"))       // should print: 0101
    println(u("101000"))     // should print: 101001
  }
}


text:
Interlace strings
Your challenge is to write a program or function that, when given two strings of equal length, swaps every other character and outputs/returns the resulting strings in either order.
Examples
"Hello," "world!" --> "Hollo!" "werld,"
"code" "golf" --> "codf" "gole"
"happy" "angry" --> "hnpry" "aagpy"
"qwerty" "dvorak" --> "qvertk" "dworay"
"1, 2, 3" "a, b, c" --> "1, b, 3" "a, 2, c"
"3.141592653589" "2.718281828459" --> "3.111291623489" "2.748582858559"
"DJMcMayhem" "trichoplax" --> "DrMcMoylex" "tJichapham"
"Doorknob" "Downgoat" --> "Doonkoot" "Dowrgnab"
"Halloween" "Challenge" --> "Hhlloeegn" "Caallwnee"

Rules

The strings will only contain ASCII chars (32-126).
The strings will always be the same length, and will never be empty.
You may accept input in any suitable format: separate parameters, items in an array, separated by one or more newlines, even concatenated. The only restriction is that one string must come fully before the other (e.g. a1\nb2\nc3 for "abc", "123" is invalid).
The output may be in either order (i.e. you can start swapping from the first or the second char), and in any valid format mentioned above. (2-item array, separated by newline(s), concatenated, etc.)

Scoring
This is code-golf, so the shortest code in bytes for each language wins.

+1 for DrMcMoylex. :D

"Dowrgnab" anagrams to "Downgrab" ( ͡° ͜ʖ ͡°)

You should point out explicitly that the "in either order" rule means swapping can begin from the first character or the second.

@DrMcMoylex Take the code, golf example. If we swap starting from second character, we get: codf, gole. Starting from first character: gole, codf.

Haskell, 37 bytes
l=(,):flip(,):l
(unzip.).zipWith3($)l

Zips the two strings, alternately swapping the characters, then unzips them.
A 37-byte recursive alternative:
(a:b)?(c:d)=a:d?b
e?_=e
a%b=(a?b,b?a)

Python, 42 bytes with I/O golfing
def f(a,b):a[1::2],b[1::2]=b[1::2],a[1::2]

Swaps every other character of the two lists. Takes as input two lists of characters, and outputs by modifying them.
l=list('cat')
m=list('dog')
print l,m

def f(a,b):a[1::2],b[1::2]=b[1::2],a[1::2]

f(l,m)
print l,m

gives
['c', 'a', 't'] ['d', 'o', 'g']
['c', 'o', 't'] ['d', 'a', 'g']

That's clever. Do you see the input/output formats as too flexible?

@ETHproductions Not sure, it might be mostly Python-specific that lists are so much manipulable than strings.

Vim, 18, 17 bytes
qqyljvPkvPll@qq@q

Try it online!
This uses the V interpreter because of backwards compatibility. Input comes in this format:
string1
string2

Explanation:
 qq                 " Start recording in register 'q'
   yl               " Yank one letter
     j              " Move down a row
      vP            " Swap the yanked letter and the letter under the cursor
        k           " Move back up a row
         vP         " Swap the yanked letter and the letter under the cursor
           ll       " Move two letters to the right. This will throw an error once we're done
             @q     " Call macro 'q' recursively
               q    " Stop recording.
                @q  " Start the recursive loop

Cut two letters by using x instead of yl and then jus P instead of second vP: lqqxjvPkPll@qq@q

@lukasz I had tried that initially, but for whatever reason, that runs it too many times and swaps the last letters when it shouldn't. I'll look into it some more though

Works for me http://v.tryitonline.net/#code=bHFxeWxqdlBrdlBsbEBxcUBx&input=REpNY01heWhlbQp0cmljaG9wbGF4

@ŁukaszNiemier That link has the same code as I posted. Did you hit the [save] button? Either way, it's not working for me. The real reason why is because when you x the last character on the line, it moves your cursor to the left, messing up the placement of the swap.

05AB1E, 11 10 bytes
øvyNFÀ}})ø

Try it online!
Explanation
input = ["code", "golf"] used as example.
ø             # zip strings into list of pairs
              # STACK: ['cg', 'oo', 'dl', 'ef']
 vy           # for each pair
   NFÀ        # rotate left index times
      }}      # end-if, end-loop
              # STACK: 'cg, 'oo', 'dl', 'fe'
        )ø    # wrap in list and zip
              # OUTPUT: ['codf', 'gole']

Haskell, 41 bytes
(a:b)#(c:d)=(a,c):d#b
_#_=[]
(unzip.).(#)

Returns a pair with the strings. Usage example: ( (unzip.).(#) ) "Hello," "world!"-> ("Hollo!","werld,").
Simple recursive approach: take the first char of each string as a pair and append a recursive call with the (rest of the) strings swapped. unzip makes a pair of lists out of the list of pairs.

Perl, 48 bytes
Bytecount includes 47 bytes of code and -p flag.
say<>=~s%.\K(.)%"s/.{$-[0]}\\K(.)/$1/;\$1"%geer

Run with -p and -E flag. Expect each string on a different line :
perl -pE 'say<>=~s%.\K(.)%"s/.{$-[0]}\\K(.)/$1/;\$1"%geer' <<< "Hello
World"

Explanations :
-p : capture input in $_ and prints it at the end. (to get and print the first string)
<> : get a line of input. (to get the second string).
=~ : apply a regex to <> : s%%%geer, where thanks to r the modified string is returned (and then printed thanks to say).
The regex :
.\K(.) finds two characters, and will replace the second one with the result of the evaluation of this code "s/.{$-[0]}\\K(.)/$1/;\$1" :
The first part, s/.{$-[0]}\\K(.)/$1/ applies a regex to $_ : .{$-[0]} skips the first characters to get to the same point as the outer regex (since $-[0] contains the index of the first capture group, so in that case the index of the characters to substitute), and then we capture a char with (.) and replace it with the character of the outer regex ($1). And then we add $1 so the result of "s/.{$-[0]}\\K(.)/$1/;\$1" is the character we captured in the inner regex.
You may have noticed that $1 refer to the character we want to replace in both strings (so two different characters), so we play with /ee modifier of the regex which evaluates the right side of the regex twice : the first one will substitute only the $1 that isn't preceded by the \.

Python, 55 bytes
lambda a,b:[(-~len(a)/2*s)[::len(a)+1]for s in a+b,b+a]

Slicing!
58 bytes:
def f(a,b):n=len(a);print[(s*n)[:n*n:n+1]for s in a+b,b+a]

64 bytes:
f=lambda a,b,s='',t='':a and f(b[1:],a[1:],s+a[0],t+b[0])or[s,t]

Recursively accumulates the characters of the two strings into s and t, and outputs the pair of them at the end. The alternation is done by switching the input strings each recursive call. Outputting a space-separated string was the same length:
lambda a,b,s='',t=' ':a and f(b[1:],a[1:],s+a[0],t+b[0])or s+t

This narrowly beat out a different recursive strategy of alternately taking characters from each string, with each of the two possible strings as the first one. (65 bytes)
g=lambda a,b:a and a[0]+g(b[1:],a[1:])
lambda a,b:(g(a,b),g(b,a))

Jelly, 5 bytes
żṚż¥/

Input is as separate arguments, output is concatenated.
Try it online! or verify all test cases.
How it works
żṚż¥/  Main link. Left argument: s (string). Right argument: t (string)

ż      Zipwith; yield the array of pairs of corresponding characters of s and t.
   ¥   Combine the two links to the left into a dyadic chain:
 Ṛ         Reverse the chain's left argument.
  ż        Zip the result with the chain's right argument.
    /  Reduce the return value of the initial ż by the quicklink Ṛż¥.

MATL, 11 10 9 8 bytes
Thanks to ETHproductions for 1 byte off!
"@X@YS&h

Input is a 2D array containing the two strings, such as: ['Halloween'; 'Challenge']. The output strings are in reverse order.
Try it online!
Explanation
        % Input 2D array implicitly
"       % For each column
  @     %   Push current column
  X@    %   Push iteration index, starting at 1
  YS    %   Circularly shift the column by that amount
  &h    %   Concatenate horizontally with (concatenated) previous columns
        % End implicitly
        % Display implicitly

Old version: 9 bytes
tZyP:1&YS

Explanation
        % Take input implicitly
t       % Duplicate
        % STACK: ['Halloween'; 'Challenge'], ['Halloween'; 'Challenge']
Zy      % Size
        % STACK: ['Halloween'; 'Challenge'], [2 9]
P       % Flip array
        % STACK: ['Halloween'; 'Challenge'], [9 2]
:       % Range. Uses first element of the array as input
        % STACK: ['Halloween'; 'Challenge'], [1 2 3 4 5 6 7 8 9]
1&YS    % Circularly shift each column by those amounts respectively
        % STACK: [Caallwnee';'Hhlloeegn']
        % Display implicitly

Jelly, 9 8 6 bytes
Thanks to Dennis for saving 2 bytes!
Zṙ"J$Z

Uses the Jelly encoding.
Try it online!

You can use ṙ"J$ instead of Ėṙ@/€. Also, separating the string is not required, so you can drop the Y.

@Dennis Ahh, that's neat. Thanks! :)

V, 12 bytes
lòyljvPkvPll

Try it online!
Nothing too interesting, just a direct port of my vim answer so I can compete with (but not beat) 05AB1E.

Pyke, 9 bytes
,Fo2%I_(,

Try it here!
          - o = 0
,         -   transpose(input)
 F     (  -  for i in ^:
  o2%     -    (o++ %2)
     I_   -   if ^: i = reverse(i)
        , - transpose(^)

JavaScript (ES6), 51 54
Edit 3 bytes saved thx @Neil
Function with array input/output
p=>p.map((w,i)=>w.replace(/./g,(c,j)=>p[i+j&1][j]))

I like this one more, but it's 55 (2 strings in input, array in output)
(a,b)=>[...a].reduce(([p,q],c,i)=>[q+c,p+b[i]],['',''])

Test

f=
p=>p.map((w,i)=>w.replace(/./g,(c,j)=>p[i+j&1][j]))

function go() {
  var a=A.value, b=B.value
  if (a.length == b.length)
    O.textContent = f([a,b]).join('\n')
  else
    O.textContent = '- different length -'

}

go()
<input id=A value='Hello,'><input id=B value='world!'>
<button onclick='go()'>go</button>

replace saves you 3 bytes: p=>p.map((w,i)=>w.replace(/./g,(c,j)=>a[i+j&1][j])).

Pyth, 8 bytes
C.e_FbkC

Try it online: Demonstration
Transposes the words, reverses each pair of letters 'current index'-times, transpose again.

JavaScript (ES6), 55 bytes
f=([c,...s],[d,...t],o="",p="")=>c?f(t,s,o+c,p+d):[o,p]

I wanted to do something clever with using regexp to replace alternate characters but that ended up taking 67 57 bytes:
a=>a.map((s,i)=>a[+!i].replace(/.(.?)/g,(_,c,j)=>s[j]+c))

Nice. I had f=([a,...A],[b,...B])=>a?[a+f(B,A)[0],b+f(A,B)[0]]:[""] for the same length.

I hoped to do a lot better, but no way, just 1 less. Time to post a non recursive answer

@edc65 Nice idea to use map, it shaved 10 bytes off my regexp answer. Still too long though.

Java, 132 103 100 bytes
Thanks to  Kevin Cruijssen for suggesting returning the array (among other improvements) and saving 29 bytes! Also Olivier Grégoire for 3 bytes!
char[]c(char[]s,int l){for(int o=l;o-->0;)if(o%2>0){char t=s[o];s[o]=s[l+o+1];s[l+o+1]=t;}return s;}

Called like this:
public static void main(String[] args) {
    System.out.println(c("Hello,world!".toCharArray(), 5)); // 5 is the length of each "String"
}

Output:
Hollo,werld!
Takes advantage of the fact that input can basically be formatted in any way (in this case, a single char array of Strings that are delimited by a comma), and pretty lenient output rules as well.

Hi, original input format you've got there. You can golf it some more though: char[]c(char[]s,int l){for(int o=l,t;o-->0;)if(l%2>0){t=s[l];s[l]=s[l+o+1];s[l+o+1]=(char)t;}return s;} (103 bytes) with the output being returned instead of printed directly. Example input: System.out.println(c("Hello,world!".toCharArray(), 5));; Example output: Hollo,werld!.

True enough, I hadn't considered just returning the char array for some reason. That's great!

The result should be Hollo!werld, and not Hollo,werld! (the punctuation is incorrect). I believe this can be fixed with a input value of 6 instead of 5.

Since you cast t to char, why don't you declare it in the for loop directly as a char? You'd spare a few bytes doing so.

Unfortunately you can't declare the char within the for-loop initializer, but you inspired me to check if declaring the char separately would be shorter than the cast and it indeed is by 1 byte.

I didn't mean in the for loop initializer, but when you first use t: char t=s[l];. You don't use it elsewhere. For a concrete example, look at my own answer.

Ah okay I misunderstood you. You're right, that saves 3 bytes!

Suggest s[o]^=s[l-~o];s[o]^=s[l-~o]^=s[o]; instead of char t=s[o];s[o]=s[l+o+1];s[l+o+1]=t;

Perl, 40 bytes
Includes +1 for -n
Give strings as lines on STDIN
interlace.pl
hello
world
^D

interlace.pl
#!/usr/bin/perl -n
s/./${1&$.+pos}[pos]=$&/seg}{print@0,@1

PowerShell v2+, 82 bytes
param($a,$b)$i=0;[char[]]$a|%{$c+=($_,$b[$i])[$i%2];$d+=($b[$i],$_)[$i++%2]};$c;$d

Still golfing... Nope. Can't seem to golf this down any without using a regex like other answers (boo on copying algorithms).
So we take $a and $b as strings, set index $i to 0, cast $a as a char-array, and send it through a loop |%{...}. Each iteration, we're string-concatenating onto $c and $d by indexing into an array-select (i.e., so it alternates back and forth). Then, we leave $c and $d on the pipeline, and output via implicit Write-Output happens at program completion.

PHP, 79 Bytes
for(;$i<=strlen(($a=$argv)[1]);$y.=$a[2-$i%2][$i++])echo$a[1+$i%2][+$i]??" $y";

Previous Version PHP, 82 Bytes
for(;$i<strlen(($a=$argv)[1]);$y.=$a[2-$i%2][$i++])$x.=$a[1+$i%2][$i];echo"$x $y";

for(...)echo$a[1+$i%2][$i];echo" $y"; (-2)

building off of Titus's comment for(;$i<=strlen(($a=$argv)[1]);$y.=$a[2-$i%2][$i++])echo$a[1+$i%2][$i]??" $y"; is a further -2, though it requires php 7

@user59178 nice but you need 1 Byte more

do you? it works for me, you just get a Notice: String offset cast occurred in Command line code on line 1

@user59178 Yes to print the first letter of the first word

as I say, it works fine for me, there are just 3 notices between that first letter and the rest of the output so if you don't have error reporting turned off it's easy to miss.

@user59178 notices are still (and I guess always will be) turned off by default

C, 124 bytes
main(c,v)char**v;{char a[99],b[99];for(c=0;v[1][c]^0;++c){a[c]=v[1+c%2][c];b[c]=v[2-c%2][c];}a[c]=0;b[c]=0;puts(a);puts(b);}

Call with:
program.exe string1 string2

String length is limited to 98 characters.

Octave, 64 61 bytes
@(x)reshape(x((t=1:end)+(2*mod(t,2)-1).*(mod(t-1,4)>1)),2,[])

Anonymous function that inputs a 2D char array with each string in a row, and produces the output in the same format.
Try it at Ideone.

Racket 208 bytes
(let((sl string->list)(ls list->string)(r reverse))(let p((s(sl s))(t(sl t))(u'())(v'())(g #t))(if(null? s)
(list(ls(r u))(ls(r v)))(p(cdr s)(cdr t)(cons(car(if g s t))u)(cons(car(if g t s))v)(if g #f #t)))))

Ungolfed:
(define (f s t)
  (let ((sl string->list)                ; create short names of fns
        (ls list->string)
        (r reverse))
    (let loop ((s (sl s))                ; convert string to lists
               (t (sl t))
               (u '())                   ; create empty new lists
               (v '())
               (g #t))                   ; a boolean flag
      (if (null? s)                      ; if done, return new lists converted back to strings
          (list (ls (r u))
                (ls (r v)))
          (loop (rest s)
                (rest t)                 ; keep adding chars to new lists alternately
                (cons (first (if g s t)) u)
                (cons (first (if g t s)) v)
                (if g #f #t))            ; alternate the boolean flag
          ))))

Testing:
(f "abcdef" "123456")

Output:
'("a2c4e6" "1b3d5f")

Above is recursive version.
Iterative version:
(let*((sl string->list)(ls list->string)(r reverse)(s(sl s))(t(sl t))(l'())(k'())(p(λ(a b g)(set! l(cons(if g a b)l))
(set! k(cons(if g b a)k)))))(for((i s)(j t)(n(in-naturals)))(p i j(if(= 0(modulo n 2)) #t #f)))(list(ls(r l))(ls(r k))))

Ungolfed:
(define (f s t)
  (let* ((sl string->list)              ; create short form of fn names
         (ls list->string)
         (r reverse)

         (s (sl s))                     ; convert strings to lists
         (t (sl t))

         (l '())                        ; create empty lists for new sequences
         (k '())

         (p (λ(a b g)                   ; fn to add chars to one or other list
              (set! l (cons (if g a b) l))
              (set! k (cons (if g b a) k)))))

    (for ((i s)(j t)(n (in-naturals)))  ; loop with both strings
          (p i j                        ; add to new lists alternately
             (if (= 0 (modulo n 2)) #t #f)))

    (list (ls (r l))                  ; convert reversed lists to strings
          (ls (r k)))))

Lithp, 120 characters (+3 for -v1 flag)
Line split in 2 for readability:
#P::((invoke P "map" (js-bridge #W,I::(replace W (regex "." "g")
     (js-bridge #C,J::(index (index P (& (+ I J) 1)) J))))))

Requires the -v1 flag to run.js as some functions are not yet part of the standard library.
Sample usage:
(
    (def f #P::((invoke P "map" (js-bridge #W,I::(replace W (regex "." "g")
                (js-bridge #C,J::(index (index P (& (+ I J) 1)) J)))))))
    (print (f (list "Hello," "world!")))
)

This sort of highlights that I haven't spent enough time on the standard library. Having to use js-bridge/1 twice and the long regex form, as well as invoking map using invoke/* all contribute to this being much longer than it needs to be.
Time to work on my standard library more I think.

C, 54 52 bytes
f(char*a,char*b,char*c){while(*c++=*a++,*c++=*b++);}

Assumes output c has already the desired length.
Usage:
main(){
 char a[]="123456";
 char b[]="abcdef";
 char c[sizeof(a)+sizeof(b)-1];
 f(a,b,c);
 puts(c);

}
If you insist on creating the output, here is a 91 bytes solution:
char*g(char*a,char*b){char*c=malloc(2*strlen(a)),*d=c;while(*c++=*a++,*c++=*b++);return d;}

Usage:
main(){
 char a[]="123456";
 char b[]="abcdef";
 puts(g(a,b));
}

Japt, 8 4 bytes
yÈéY

Try it
yÈéY     :Implicit input of array U
y        :Transpose
 È       :Map each element at 0-based index Y then transpose back
  éY     :  Rotate right Y times

q, 32 bytes
{?[;x;y]each(not\)count[x]#10b}.

k, 24 bytes
{?[;x;y]'(~:\)(#x)#10b}.

Java, 68 bytes
(a,b)->{for(int i=a.length;--i>0;){char t=a[--i];a[i]=b[i];b[i]=t;}}

Ungolfed and testing
import java.util.Arrays;
import java.util.Collection;
import java.util.function.BiConsumer;

public class Main {

  static BiConsumer<char[], char[]> func = (left, right) -> {
      for (int i = left.length; --i > 0;) {
        char temp = left[--i];
        left[i] = right[i];
        right[i] = temp;
      }
    };

  public static void main(String[] args) {
    test("Hello,","world!", "Hollo!", "werld,");
    test("code", "golf", "codf", "gole");
    test("happy", "angry", "hnpry", "aagpy");
  }

  private static void test(String left, String right, String x, String y) {
    char[] leftChars = left.toCharArray();
    char[] rightChars = right.toCharArray();
    func.accept(leftChars, rightChars);
    Collection mixed = Arrays.asList(new String(leftChars), new String(rightChars));
    if (mixed.containsAll(Arrays.asList(x, y))) {
      System.out.println("OK");
    } else {
      System.out.printf("NOK: %s, %s -> %s%n", left, right, mixed);
    }
  }
}

APL, 12
{↓(⍳⍴⊃⍵)⊖↑⍵}

Explanation: {...} defines a function, ⍵ is the right argument.
The take (↑) creates a matrix out of the two strings, then rotates each column (⊖) n times, where n is the part in parenthesis (⍳⍴⊃⍵). That's defined as the iota of the length of the first argument. (Ex: length=5 ==> 1 2 3 4 5).
So first column is rotated once, second twice (getting back to original positions), third column three times, etc...
Try it at tryapl.org

Swift 3, 129 107 bytes
func c(n:inout[String],b:inout[String]){
for(j,c)in n.enumerated(){
if j&1<1{n[j]=b[j];b[j]=c}}
print(n,b)}

Original
The function receives two arrays of strings as parameters assuming both have same length, as follows:
c(n:["c", "o", "d", "e"],b:["g", "o", "l", "f"])

Produces following output
codf gole

Edit 1:
Get rid of the internal tuple and change the parameters of the function to be inout. Instead of string concatenation manipulate the parameters directly.
Example input:
var a:Array<String> = ["c", "o", "d", "e"]
var b:Array<String> = ["g", "o", "l", "f"]

c(n:&a,b:&b)

Ouput changed to be array of strings as in:
["g", "o", "l", "e"] ["c", "o", "d", "f"]

Scala, 85 bytes
(_:String)zip(_:String)zip(Stream from 0)map{case(t,z)=>if(z%2==0)t else t.swap}unzip

take an anonymous string parameter, zip it with another string parameter, zip it with an stream of natural numbers, swap every second tuple of chars and unzip to get a tuple of sequences of chars

C, 150 bytes
I used the typical omissions of header files and main()'s return type and return statement. It throws a warning, but compiles without issue. I also used a GCC-specific trick that allows array declarations with variable expressions.
The program expects the strings from the command line, and as such, the program should be run with ./a.out string1 string2.
main(int a,char**v){int x=strlen(v[1]);char s[x],t[x],c;strcpy(s,v[1]);strcpy(t,v[2]);for(a=0;a<x;++a)if(a%2)c=s[a],s[a]=t[a],t[a]=c;puts(s),puts(t);}

Or more legibly,
main(int a,char**v){
    int x=strlen(v[1]);
    char s[x],t[x],c;
    strcpy(s,v[1]);strcpy(t,v[2]);
    for(a=0;a<x;++a)
        if(a%2)c=s[a],s[a]=t[a],t[a]=c;
    puts(s),puts(t);
}

Mathematica, 51 bytes
Takes input as an array of two arrays of characters, with output in the same format. The function simply constructs the new array using a (mod 2) operation.
Table[#[[Mod[j+i,2]+1,j]],{i,2},{j,Length@#[[1]]}]&

QBasic 4.5, 172 bytes
Ouch, this one gets painful with the ol' QBasic...
DEFSTR A-D:INPUT A,B
IF LEN(A)MOD 2=1 THEN A=A+" ":B=B+" "
FOR x=1 TO LEN(A) STEP 2
C=C+MID$(A,x,1)+MID$(B,x+1,1):D=D+MID$(B,x,1)+MID$(A,x+1,1):NEXT:?RTRIM$(C),RTRIM$(D)

Fun fact: Using DEFSTR saved more bytes than it cost because now I could use A instead of a$.

QBIC, 112 bytes
QBIC can streamline a lot of the QBasic boilerplate, but the main MID$engine still needs to be done in QBasic because QBIC lacks a substring-function. Still, saves me 60 bytes.
;;_LA|~a%2=1|A=A+@ | B=B+C][1,a,2|X=X+$MID$(A$,b,1)+MID$(B$,b+1,1):Y$=Y$+MID$(B$,b,1)+MID$(A$,b+1,1)|]?_tX|,_tY|

MIND$ => MIN$ in text.

Husk, 7 bytes
Tz*İ_ze

Try it online!
Outputs are reversed.

Ly, 11 bytes
ir>ir[<o>o]

Try it online!
This takes the two strings on separate input lines, and outputs the interlaced strings concatenated together.  At a high level...  It reads the two strings onto separate stacks, then just loops printing the top the each stack.
ir          - read first string onto the stack, reverse it
  >ir       - switch to new stack, read second string and reverse it
     [    ] - loop until the stack is empty
      <o    - switch to first stack and print a char
        >o  - switch to the second stack and print a char