[Question]
  [
Steganography hides a given message inside a given carrier, producing a package that does not look suspicious. For this challenge, you will write a program that takes an ASCII message and an ASCII carrier as input, and return or print a package that is identical to the carrier except characters corresponding to the message are doubled, in the same order that they appear in the message.
Rules:
1. If the carrier already contains sequences of the same character more than once, and they are not used to encode a character of the message, the program will reduce them to a single character.
2. If the carrier does not contain the message characters in the right order, the program may return nothing, the carrier itself, or an error.
3. You may assume that the message and carrier are non-empty ASCII strings.
4. Capitalization matters: A is not equivalent to a.
5. When more than one package is valid, your program may output any or all of them.
6. Space is a character like any other character.
Test cases:
```
Message      Carrier              Package
"hi"         "has it arrived?"    "hhas iit arived?" OR "hhas it ariived?"
"sir"        "has it arrived?"    "hass iit arrived?"
"foo"        "has it arrived?"    "" OR "has it arrived?" OR an error.
"Car"        "Cats are cool."     "CCaats arre col."
"car"        "Cats are cool."     "" OR "Cats are cool." OR an error.
"Couch"      "Couch"              "CCoouucchh"
"oo"         "oooooooooo"         "oooo"
"o o"        "oooo oooa"          "oo  ooa"
```
This is code golf, so fewest bytes wins.
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 28 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ẹⱮŒp<ƝẠ$ƇṪ
nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç?
```
A full program taking `carrier` and `message` as command line arguments which prints the result  
(For a non-packable `message` prints the unchanged `carrier`).
**[Try it online!](https://tio.run/##AVgAp/9qZWxsef//4bq54rGuxZJwPMad4bqgJMaH4bmqCm7GnSvDp@G5rMKlYeKBuOG4nzDhuKTDp8Kmw7DCucOnP////yJoYXMgaXQgYXJyaXZlZD8i/yJzaXIi "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8///hrp2PNq47OqnA5tjch7sWqBxrf7hzFVfesbnah5c/3Lnm0NLER407Hu6Yb/Bwx5LDyw8tO7zh0M7Dy@3/H16u/6hpTeT//9HRShmJxQqZJQqJRUWZZakp9ko6CkoZmUqxOlwKWOWKM4twS6bl50MlnRNLioFSqQrJ@fk5eiA558QinHLJCLn80uQMsHIwAyKYDwcgGbgdIAEFIE4EiyoAhWMB "Jelly – Try It Online").
### How?
```
ẹⱮŒp<ƝẠ$ƇṪ - Link 1, helper function to find the indices to double: carrier, message
           -                               e.g. "programming", "rom"
 Ɱ         - map across message with:
ẹ          -   indices of                       [[2,5], [3], [7,8]]
  Œp       - Cartesian product                  [[2,3,7],[2,3,8],[5,3,7],[5,3,8]]
        Ƈ  - filter keep if:
       $   -   last two links as a monad:
     Ɲ     -     for neighbours:
    <      -       less than?                    [1,1]   [1,1]   [0,1]   [0,1]
      Ạ    -     all truthy?                     1       1       0       0
           -                                    [[2,3,7],[2,3,8]]
         Ṫ - tail (if empty yields 0)                    [2,3,8]
nƝ+çṬ¥a⁸ḟ0Ḥç¦ð¹ç? - Main Link: carrier, message
                ? - if...
               ç  - ...condition: last Link (the helper function) as a dyad
             ð    - ...then: perform the dyadic chain to the left (described below)
              ¹   - ...else: do nothing (yields carrier)
                  - (the then clause:)
 Ɲ                - for neighbours in the carrier
n                 - not equal?
     ¥            - last two links as a dyad:
   ç              -   call last Link (the helper function) as a dyad
    Ṭ             -   untruth (e.g. [2,5] -> [0,1,0,0,1])
  +               - add (vectorises)
      a⁸          - logical AND with carrier
        ḟ0        - filter out zeros
            ¦     - sparse application...
           ç      - ...to indices: call last Link (the helper function) as a dyad
          Ḥ       - ...do: double (e.g. 'x' -> 'xx')
```
[Answer]
# JavaScript (ES6), 71 bytes
Takes input as `(message)(carrier)`.
```
s=>g=([c,...C],p)=>c?(c==s[0]?(s=s.slice(1),c)+c:p==c?'':c)+g(C,c):s&&X
```
[Try it online!](https://tio.run/##fZAxa8MwEIX3/IpDQywRV2lXB8WD6RzwVAgZxEWxXdwo6JRAKfntrmzLpQltDiyk7969Z@ldXzSha07@6Wj3pjuojtS6UnyLqZSy2KUnodaYc1SKts@7nJMiSW2Dhr@IFMUCs5NSmCdJFg4VLwLLaD5/67whDwo4pYAC1Bq@wLvPsKI9km2NbG3FD5wERyFWcAXUHmtuxJ0keS3LTZlBAgsw8sMQ6SqIrnCdzfoMzuqGpRCK1Zqg8aCday5mnzMBy2WgAx74iGFTTnSAI41m1LjB7T8zTZOZu5k7WPtoLobe9Xqoj2Ccs05Go0LHHyi0pyA14TVsKxmMRkWhRz40Ao9j@HhszL/v/RVvz1gHp7iBn5rirT2fEet6Co73hrCZiv0aGM6TFOIb9RDCpxncSAF61n0D "JavaScript (Node.js) – Try It Online")
---
# Alternate version, 66 bytes
If we can take the message as an array of characters:
```
s=>g=([c,...C],p)=>c?(c==s[0]?s.shift()+c:p==c?'':c)+g(C,c):s+s&&X
```
[Try it online!](https://tio.run/##fZAxa8MwEIX3/IrDQyxhV@nsongwnQOeCiGDuMiWSxoFnRIoJb/dlW25NKHNgYz03bv3ZL2riyJ03ck/He1e943sSa5bybaYCyGqXX7ico0lQylp@7wrSZDpGs94hsVJSizTtECetazKkReU0XL51ntNHiQwygE5yDV8gXef4Yv2SPagxcG2rGHbkEA7zpDzF7gCKo@GaX6nS1/relMXkEIGWnxoItUG0RWui8UQxBLTJTmESowi6Dwo57qL3pcJh9Uq0BGPfMKwqWc6wolGM@rc6PafmaLZzN3MNdY@mouhd70BqiNo56wT0ahS8QKV8hSkOryGPYgEJqOqUhMfG4HHMXw8NuXf9/6Kt2c0wSlu4KfmeGvPZ0Rj5uD43xA2cyW/BsbzLIX4RgOEsFQCN1KAgfXf "JavaScript (Node.js) – Try It Online")
---
***Edit**: Thanks to @tsh for noticing that I forgot to remove some code when switching from non-recursive to recursive versions.*
[Answer]
## Haskell, ~~124~~ ~~121~~ ~~107~~ ~~101~~ ~~97~~ ~~95~~ 90 bytes
```
(#).(++"ü")
"ü"#[]=[]
p@(m:n)#e@(c:d)|m/=c=c:p#snd(span(==c)d)|m==n!!0=m:m:n#d|1<2=m:n#e
```
Raises the "Non-exhaustive patterns" exception if the carrier does not contain the message.
[Try it online!](https://tio.run/##jc6/bsMgEAbw3U9xgQ6gqOmf0eqpkbJm65hkOAGOUW1Axs7kR@vW9yoxlbzEGYLEdyd9PyFqit@maVKFxyS43Ij1mv3@MFnk5IcTHk5F2Iq2dJKbrVCllmP7ggpVGXh0WsRATiAqmQtEt1q9YltOnuvx7eMd82ZSS9YBgvYFAISh/@q7vYMnqIDVlk1BEWwP1HX2YvQnW7Jou4fcjrLbUR8nZUB532zuMT@oms1z2XvPcsznnoCZwHSJFUtS/b9y@@f0p6qGzjE9qxCu "Haskell – Try It Online")
Edit: -5 bytes thanks to @Laikoni.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 67 bytes
```
+`(.)(\1*)\1*(.*¶)(?(\1)(\1(\2)))(.*)$(?!¶)
$1$4$5¶$3$6
M!s`.*¶$
¶
```
[Try it online!](https://tio.run/##K0otycxL/P9fO0FDT1MjxlBLE4g19LQObdPUsAfyQWIaMUaamppAQU0VDXtFoAyXiqGKiYrpoW0qxipmXL6KxQkgDSpch7Zx/f@fkViskFmikFhUlFmWmmLPlZEJAA "Retina 0.8.2 – Try It Online") Takes the carrier on the first line and the message on the second line. Explanation:
```
+`(.)(\1*)\1*(.*¶)(?(\1)(\1(\2)))(.*)$(?!¶)
$1$4$5¶$3$6
```
Process runs of 1 or more identical characters of the carrier. If there is also a run of 1 or more of the same characters in the message, then append the shorter of the two runs to the output in duplicate, otherwise append a single character of the carrier to the output. Each run of output characters is terminated with a newline to distinguish it from the input. The `(?!¶)` at the end prevents the regex from thinking the carrier is the message once the message is exhausted, as normally `$` is allowed to match where `¶$` would match.
```
M!s`.*¶$
```
Delete everything if the message wasn't completely encoded.
```
¶
```
Remove the newlines from the output.
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 118 bytes
```
import StdEnv,StdLib
$[][]=[]
$[u:v]b#(_,w)=span((==)u)v
|b%(0,0)==[u]=[u,u: $if(v%(0,0)<>b%(1,1))w v(tl b)]=[u: $w b]
```
[Try it online!](https://tio.run/##PY5LC8IwEITv/RUBK00g0vZajCc9CL31GIIkfUggj2KbFMHfbozUupfZnflgtlU9N0HbzqkeaC5NkHq0jxk0c3cxHkeppUhSyigjlMXFVZ6JHbzhBZFp5AZCQpBDPnmJPSxwgQihLrIOuwqkcoB@tY@nmJe4RGgBHs4KCPSlIrMAwUIz89hKQApoZm3GNsnzn7XNPwrvdlD8PoXDtQ7np@FatuuxPv0B "Clean – Try It Online")
Takes the carrier first, then the message.
Errors with `Run time error, rule '$;2' in module 'main' does not match` if message won't fit.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 73 bytes
```
f=->m,c,b=p{x,*c=c;x ?(x==m[0]?x+m.shift: x==b ?'':x)+f[m,c,x]:m[0]?x:''}
```
[Try it online!](https://tio.run/##jZLRaoMwFIbv@xRnbuC2ZrJrh/XCBxjsVryIZ5EItZFER0bbZ3fHpFltx6ABkXz/@f9zOESP9fc0NdnLpmPI6qzfW/aMGb5ZyB9tlnXla5XbdZcY2TZDCoRqyOM4tU/rppw9tkp9URrHx6lclZFsIwbhRJIbaAfgWrdf4jOPKnbvuROc4gV4/wjUQU8pz7T6HPh/HjchT/9aG6VusJ5aX6kz5DsQWiudUFbBl2MUfDBUKwCV2iYhinjBveIkUsiJNzn9FFfqnyHUiDKEnW4h4bzzolBqHBGlnNsvdwB0C@fC6LirhuXKZgr08csuxAFmuqoSwVHuD/QUDj3Qk0hQcm0Y@n@lhcFRQP9wd5x@AA "Ruby – Try It Online")
Recursive function, takes inputs as array of characters.
For once I was hoping to make use of Ruby's built-in `squeeze` method that contracts consecutive runs of the same character to a single instance. But unfortunately, nope - the last two test cases screwed everything so badly, that I had to resort to a completely different approach, and this turned out to be basically a port of [Arnauld's answer](https://codegolf.stackexchange.com/a/177217/78274).
[Answer]
# Powershell, 134 bytes
```
param($m,$c)$c-csplit"([$m])"|%{$i+=$o=$_-ceq$m[+$i]
if($o-or$_-cne"`0$h"[-1]){$h+=($_-replace'(.)(?=\1)')*($o+1)}}
$h*!($i-$m.Length)
```
The script returns the `empty string` if the carrier does not contain the message characters in the right order.
Less golfed test script:
```
$f = {
param($message,$carrier)
$carrier-csplit"([$message])"|%{                # split by chars of the message, chars itself included ([])
    $offset=$_-ceq$message[+$i]                 # 0 or 1 if current substring is a current message char (case-sensitive equality)
    $i+=$offset                                 # move to next message char if need it
    if($offset-or$_-cne"`0$h"[-1]){             # condition to remove redundant doubles after message char: arrrived -> arrived, ooo -> oo, etc
                                                # `0 to avoid exception error if $h is empty
        $h+=($_-replace'(.)(?=\1)')*($offset+1) # accumulate a double message char or a single substring without inner doubles: arried -> arived, anna -> ana, etc
    }
}
$h*!($i-$message.Length)                        # repeat 0 or 1 times to return '' if the carrier does not contain the message characters in the right order
}
@(
    ,('hi'         ,'has it arrived?'    ,'hhas iit arived?', 'hhas it ariived?')
    ,('hi?'        ,'has it arrived?'    ,'hhas iit arived??', 'hhas it ariived??')
    ,('sir'        ,'has it arrived?'    ,'hass iit arrived?')
    ,('foo'        ,'has it arrived?'    ,'')
    ,('Car'        ,'Cats are cool.'     ,'CCaats arre col.')
    ,('car'        ,'Cats are cool.'     ,'')
    ,('Couch'      ,'Couch'              ,'CCoouucchh')
    ,('oo'         ,'oooooooooo'         ,'oooo')
    ,('o o'        ,'oooo oooa'          ,'oo  ooa')
    ,('er'         ,'error'              ,'eerorr', 'eerror')
    ,('a+b'        ,'anna+bob'           ,'aana++bbob')
) | % {
    $message,$carrier,$expected = $_
    $result = &$f $message $carrier
    "$($result-in$expected): $result"
}
```
Output:
```
True: hhas iit arived?
True: hhas iit arived??
True: hass iit arrived?
True:
True: CCaats arre col.
True:
True: CCoouucchh
True: oooo
True: oo  ooa
True: eerror
True: aana++bbob
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 69+12 = 81 bytes
```
g(char*m,char*_){for(;*_;++_)*m-*_?_[-1]-*_&&p*_):p p*m++));*m&&0/0;}
```
Compile with (12 bytes)
```
-Dp=putchar(
```
[Try it online!](https://tio.run/##hZJNboMwEIX3nGLEAtn8pEmWRVEW9BZNhSw3YEsBIwPdRLl66XgCKahJMxKY4c379GyQSSnlMJRMKmHDKqYl5@fCWJaGeRpFOQ@rJMz3@Xuy@cCHIGhw4LWBJqyiiPM0rIJg/bJOL0MldM04nD1dd3C01tgN7GAde4BF/db1qeeVzFfaj30lWtAdCGv11/Fz7/PUa/quZf6hVqSRSBoAUzpeGvihdhaHa7V9whPtxBuBDD0PgLoAdt0AbgcQXxjzP56mYV4MPXfxcKHEmXCJM9G1KB9BGnNazYlZJq4aiacVEtESLw1/Am/HwPIJ/U5e@YA@5TW9VI5J6yKoMX0vpVI3FM3EdJ99IzpDc6s5w/WwjIOn9zs7p8CEAbzEkgL4TiwocMXQ7Ei5DN@yOImyHZK3Zodm99ezHw "C (gcc) – Try It Online")
```
g(char*m,char*_){
    for(;*_;++_)        //step through _
        *m-*_?          //check if character should be encoded
            _[-1]-*_&&  //no? skip duplicates
                p*_)    //    print non-duplicates
        :p p*m++));     //print encoded character twice
    *m&&0/0;            //if m is not fully encoded, exit via Floating point exception
}
```
]