Everyone Knows AdFly and their Sister Sites.

If we see the Page Source of an ad.fly site we can see this perticular line:
Believe it or not This is actually the Encoded url which you would skip to.

The Algorithm is as Follows:
```
1) The ysmm value is broken like this

ysmm   = 0 1 2 3 4 5 6 7 8 9  = "0123456789"
code1  = 0   2   4   6   8    = "02468"
code2  =   9   7   5   3   1  = "97531"

2) code1+code2 is base64 Decoded

3) The result will be of this form :
https://adf.ly/go.php?u=

4)  has to be further decoded and the result is to be returned
```

Your Task:

```
Make a function to Encode text to ysmm value.

and a function to Decode ysmm value.
```

Note: Take random values for The first 2 int values.
I personally hate trivial error checking like giving integer input in place of string. 

```
Input For Decoder & Encoder: Strings
Return "Invalid" for invalid Strings
```

Difficulty: EASY

Starter code:
def adFly_decoder(sc):
	

Solutions:
import base64
import binascii
import math
from itertools import zip_longest

def adFly_decoder(sc):
	code1 = ''
	code2 = ''
	flip = False
	for c in sc:
		if flip:
			code2 += c
		else:
			code1 += c
		flip = not flip
	try:
		url = base64.b64decode(code1 + code2[len(code2)::-1])
	except binascii.Error:
		return 'Invalid'
	try:
		dec = base64.b64decode(url[26:])
	except binascii.Error:
		return 'Invalid'
	return str(dec, 'utf-8')

def adFly_encoder(url):
	prefix = '96https://adf.ly/go.php?u='
	full = str.encode(prefix) + base64.b64encode(str.encode(url))
	enc = base64.b64encode(full)
	cut = math.ceil(len(enc) / 2)
	code1 = str(enc[:cut + 1], 'utf-8')
	code2 = str(enc[len(enc):cut:-1], 'utf-8')
	swp = ''.join((i + (j or '') for (i, j) in zip_longest(code1, code2)))
	return swp


from base64 import b64decode, b64encode
from random import randint

def adFly_decoder(sc):
	return b64decode(b64decode(sc[::2] + sc[::-2])[26:]).decode('utf-8') or 'Invalid'

def adFly_encoder(url):
	url = f'{randint(0, 99):02d}https://adf.ly/go.php?u={url}'.encode('utf-8')
	encoded = b64encode(url[:26] + b64encode(url[26:])).decode('utf-8')
	length = len(encoded) // 2
	return ''.join((x + y for (x, y) in zip(encoded[:length], encoded[:length - 1:-1])))


import base64

def adFly_decoder(sc):
	code1 = ''
	code2 = ''
	flg = True
	for ch in sc:
		if flg:
			code1 += ch
		flg = not flg
	flg = True
	for ch in sc[::-1]:
		if flg:
			code1 += ch
		flg = not flg
	try:
		s = base64.b64decode(code1 + code2).decode('utf-8')
		s = s.split('//adf.ly/go.php?u=')[1]
		return base64.b64decode(s).decode('utf-8')
	except:
		return 'Invalid'

def adFly_encoder(url):
	s = '96https://adf.ly/go.php?u='
	e_url = base64.b64encode(bytes(url, 'utf-8')).decode('utf-8')
	s += e_url
	b64 = list(base64.b64encode(bytes(s, 'utf-8')).decode('utf-8'))
	yummy = ''
	flg = True
	while b64:
		if flg:
			yummy += b64.pop(0)
		else:
			yummy += b64.pop()
		flg = not flg
	return yummy


import base64
from random import randint

def adFly_decoder(sc):
	code1 = sc[0:len(sc):2]
	code2 = sc[len(sc):0:-2]
	print(sc)
	if len(code2) - 1 >= 8:
		b = base64.b64decode(code1 + code2)
		b = str(b).split('?')
		return str(base64.b64decode(b[1][2:-1]))[2:-1]
	return 'Invalid'

def adFly_encoder(url):
	url_encoded = str(base64.b64encode(url.encode('ascii')))[2:-1]
	url_adfly = str(randint(0, 9)) + str(randint(0, 9)) + 'https://adf.ly/go.php?u=' + url_encoded
	b = base64.b64encode(url_adfly.encode('ascii'))
	b = str(b)[2:-1]
	sc1 = b[0:len(b) // 2]
	sc2 = b[len(b) // 2:][::-1]
	sc = ''
	idx = 0
	for x in range(len(b)):
		if x % 2 == 0:
			sc += sc1[idx]
		else:
			sc += sc2[idx]
			idx += 1
	return sc


import random
import base64

def adFly_decoder(sc):
	code1 = ''
	code2 = ''
	for i in range(len(sc)):
		if i % 2 == 0:
			code1 += sc[i]
		else:
			code2 += sc[i]
	code2 = code2[::-1]
	code1 += code2
	try:
		decodeStr = str(base64.b64decode(code1))[2:-1]
	except base64.binascii.Error as err:
		return 'Invalid'
	else:
		a = base64.b64decode(decodeStr[decodeStr.find('?u=') + 3:])
		return str(a)[2:-1]

def adFly_encoder(url):
	decodeStr = str(base64.b64encode(bytes(url, encoding='utf-8')))[2:-1]
	ran = random.randint(10, 99)
	modStr = str(base64.b64encode(bytes(str(ran) + 'https://adf.ly/go.php?u=' + decodeStr, encoding='utf-8')))[2:-1]
	code1 = modStr[:len(modStr) // 2]
	code2 = modStr[len(modStr) // 2:]
	res = ''
	ic1 = ic2 = 0
	for i in range(len(modStr)):
		if i % 2 == 0:
			res += code1[ic1]
			ic1 += 1
		else:
			res += code2[ic2 - 1]
			ic2 -= 1
	return res


import base64
import random
PREFIX = 'https://adf.ly/go.php?u='

def adFly_decoder(sc):
	try:
		decoded = base64.b64decode(sc[::2] + sc[1::2][::-1]).decode('utf-8')
		assert decoded[:2].isdigit()
		decoded = decoded[2:]
		assert decoded.startswith(PREFIX)
		return base64.b64decode(decoded[len(PREFIX):]).decode('utf-8')
	except:
		return 'Invalid'

def adFly_encoder(url):
	adfly_url = f"{random.randint(0, 99):02d}{PREFIX}{base64.b64encode(url.encode('utf-8')).decode('utf-8')}"
	adfly_url = base64.b64encode(adfly_url.encode('utf-8')).decode('utf-8')
	half1 = adfly_url[:(len(adfly_url) + 1) // 2]
	half2 = adfly_url[(len(adfly_url) + 1) // 2:]
	result = ''
	while half1:
		result += half1[0]
		half1 = half1[1:]
		if half2:
			result += half2[-1]
			half2 = half2[:-1]
	return result


import base64

def adFly_decoder(sc):
	code1 = ''
	code2 = ''
	for i in range(len(sc)):
		if i % 2 == 0:
			code1 = code1 + sc[i]
		else:
			code2 = code2 + sc[i]
	try:
		url = base64.b64decode((code1 + code2[::-1]).encode())[26:]
		return base64.b64decode(url).decode()
	except:
		return 'Invalid'

def adFly_encoder(url):
	plain = f'00https://adf.ly/go.php?u={base64.b64encode(url.encode()).decode()}'
	code = base64.b64encode(plain.encode()).decode()
	i = len(code) // 2
	(code1, code2) = (code[:i], code[i:][::-1])
	ysmm = ''
	for (ch1, ch2) in zip(code1, code2):
		ysmm = ysmm + ch1 + ch2
	return ysmm


import base64

def adFly_decoder(sc):
	try:
		code1 = sc[::2]
		code2 = sc[1::2]
		code2 = code2[::-1]
		decode_adfly = base64.b64decode(code1 + code2).decode('utf-8')
		encoded_url = decode_adfly.split('https://adf.ly/go.php?u=')[-1]
		return base64.b64decode(encoded_url).decode('utf-8')
	except:
		return 'Invalid'

def adFly_encoder(url):
	code = base64.b64encode(url.encode()).decode('utf-8')
	ad_fly_code = '12https://adf.ly/go.php?u=' + code
	final_code = base64.b64encode(ad_fly_code.encode()).decode('utf-8')
	l = len(final_code)
	half = l // 2
	first_half = final_code[0:half]
	second_half = final_code[half if l % 2 == 0 else half + 1:]
	second_half = second_half[::-1]
	result_string = ''
	for i in range(half):
		result_string += first_half[i]
		if i < half - 1 or l % 2 == 0:
			result_string += second_half[i]
	return result_string