I’am dealing with challenge in my study but i didn’t find solution could anyone give me hint :
import re
import string
from types import CodeType
import random
banner = """
---------------------------------------------------------------------------
"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"
`=`,'=/ `=`,'=/ `=`,'=/ `=`,'=/ `=`,'=/
y==/ y==/ y==/ y==/ y==/
,=,-<=`. ,=,-<=`. ,=,-<=`. ,=,-<=`. ,=,-<=`.
_,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' `-=_
HelixScribe
v23.7
Copyright © 2023 HelixScribe LLC.
All rights reserved.
"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"`-:-. ,-;"
`=`,'=/ `=`,'=/ `=`,'=/ `=`,'=/ `=`,'=/
y==/ y==/ y==/ y==/ y==/
,=,-<=`. ,=,-<=`. ,=,-<=`. ,=,-<=`. ,=,-<=`.
_,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' `-=_,-'-' `-=_
"""
header = """/=/ \=\ *-----------------------------------------------------------*
|=| |=| | | Chromosome |
\=\ /=/ | Base Pair |-----------------------------------------------|
`.\ /,' | | A | B | C | D | E | F |
`\. |-----------|-------|-------|-------|-------|-------|-------|
"""
bps = """ ,'/ \`. | 1 |
/=/ \=\ | 2 |
|=| |=| | 3 |
\=\ /=/ | 4 |
`.\ /,' | 5 |
,/' | 6 |
,'/ \`. | 7 |
/=/ \=\ | 8 |
|=| |=| | 9 |
\=\ /=/ | 10 |
`.\ /,' | 11 |
,/' | 12 |
,'/ \`. | 13 |
/=/ \=\ | 14 |
|=| |=| | 15 |
\=\ /=/ | 16 |
`.\ /,' | 17 |
`\. | 18 |
,'/ \`. | 19 |
/=/ \=\ | 20 |
|=| |=| | 21 |
\=\ /=/ | 22 |
`.\ /,' | 23 |
,/' | 24 |
,'/ \`. | 25 |
/=/ \=\ | 26 |
|=| |=| | 27 |
\=\ /=/ | 28 |
`.\ /,' | 29 |
`\. | 30 |""".split("\n")
footer = " ,'/ \`. *-----------------------------------------------------------*"
print(banner)
genes = "".join([random.choice(string.hexdigits.upper()) for i in range(720)])
def specimen(): pass
def gene_printer():
global genes
o = header
for b in range(30):
o += bps[b]
for c in range(6):
o += " %s-%s |" % (genes[c*30*4+b*4:c*30*4+b*4+2],genes[c*30*4+b*4+2:c*30*4+b*4+4])
o += "\n"
o += footer
print(o)
def gene_editor():
global genes
chromosome = input("Please enter the chromosome that you would like to edit (A-F): ").strip().upper()
print()
if (chromosome + " ")[0] not in "ABCDEF":
print("Error. Invalid option.")
return
base_pair = input("Please enter the starting base pair that you would like to edit (1-30): ").strip().upper()
print()
if not re.fullmatch(r'[1-9]|[12][0-9]|30',base_pair):
print("Error. Invalid option.")
return
chromosome_index = (int(base_pair)-1)*4
sequence = input("Please enter the new gene sequence: ").upper()
print()
sequence = "".join([i for i in sequence if i in string.hexdigits.upper()])
length = min(30*4-chromosome_index, len(sequence))
sequence = sequence[:length]
starting_index = 30 * 4 * (ord(chromosome) - 65) + chromosome_index
genes = genes[:starting_index] + sequence + genes[starting_index + length:]
print("Edit successful.")
def test_survivability():
global genes
specimen.__code__ = CodeType(0, 0, 0, 2, 32, 67, bytes.fromhex(genes), (None,),
('chr', 'eval'), ('', ''), '', '', 0, b'', (), ())
try:
specimen()
return True
except Exception as e:
return False
while True:
print("---------------------------------------------------------------------------")
print()
print("Select option:")
print(" 1. View genes")
print(" 2. Edit genes")
print(" 3. Test survivability")
print()
option = input("Enter number: ").strip()
print()
if option == "1":
gene_printer()
elif option == "2":
gene_editor()
dis
module, and then using it on the desired code object. It looks likeCodeType
is being used to create a code object from the bytecode ingenes
. That'd probably be a good object to disassemble.