Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Kiba.docx
Binary file not shown.
23 changes: 23 additions & 0 deletions Lab_Rab_0/Lab_Rab_0.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Lab_Rab_0", "Lab_Rab_0\Lab_Rab_0.pyproj", "{A5DB5168-E575-4710-AAED-CEF6C07B18D4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A5DB5168-E575-4710-AAED-CEF6C07B18D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5DB5168-E575-4710-AAED-CEF6C07B18D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1CA3E8D9-1FD0-43D5-9362-4D5E73D6E466}
EndGlobalSection
EndGlobal
147 changes: 147 additions & 0 deletions Lab_Rab_0/Lab_Rab_0/Lab_Rab_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
def Index(index_cod, list_cod, rotor_dict):
"""Данная функция ищет индексы по елементам в словаре.

Она нужна для более легкого поиска и оброботки значений.

"""
index_cod = [
key
for el in list_cod
for key, value in rotor_dict.items()
if el == value
]

return index_cod


def Rotor_norm(index_cod, sum):
""" Функция выступает 3-тим фиксированым ротором."""

result = [sum - x for x in index_cod]

return result


def Rotor_in(index_key,index_cod):
"""Начало входа в первую часть роторов(начало шифровки)."""
result_list = [
value
for _ in range(len(index_cod))
for value in index_key
]

result = [
x - y
for x, y in zip(index_cod, result_list)
]

return result


def Rotor_out(index_key, index_cod, count):
"""Выход и обработки значени(конец шифроки)."""
result_list = [
symbol
for _ in range(len(index_cod))
for symbol in index_key
]

result=[x + y for x, y in zip(index_cod, result_list)]

return result


def Sum_chek(index_cod):
"""Отдельная функция для проверки диапазона кодируемых индексов."""
for key in range(len(index_cod)):

if index_cod[key] < 0:
index_cod[key] = index_cod[key] + 38

elif index_cod[key] > 38:
index_cod[key] = index_cod[key] - 38

return index_cod


def Coder(index_key, index_cod, count, sum):
"""Функция реализована для упращения работы.

Может виступать как для шифровки так и для дешифровки.

"""

for x in index_key:
index_cod = Rotor_in(index_key, index_cod)
index_cod = Sum_chek(index_cod)

index_cod = Rotor_norm(index_cod, sum)

for x in index_key:
index_cod = Rotor_out(index_key, index_cod, count)
index_cod = Sum_chek(index_cod)

return index_cod


def Unindex(index_cod, list_cod, rotor_dict):
"""Ищет по индексу буквы в словаре и перености их в лист."""

list_cod = [
value
for el in index_cod
for key, value in rotor_dict.items()
if el == key
]

return list_cod


rotor_dict = {
0:'0',6:'F',12:'L',18:'S',24:'Y',30:'4',36:'_',
1:'A',7:'G',13:'M',19:'T',25:'Z',31:'5',37:'.',
2:'B',8:'H',14:'O',20:'U',26:'N',32:'6',38:',',
3:'C',9:'Q',15:'P',21:'V',27:'1',33:'7',
4:'D',10:'J',16:'I',22:'W',28:'2',34:'8',
5:'E',11:'K',17:'R',23:'X',29:'3',35:'9'
}
# Инициализация словаря для индексации.

string_cod = input("Введите кодируемое слово: ").upper()
string_key = input("Введите слово шифровки: ").upper()
# Ввод кодируемого слова и его ключа.

space = string_cod.split()
string_cod = '_'.join(space)
space = string_key.split()
string_key = '_'.join(space)
# Замена пробелов для возможности их кодировки.

count = len (string_key)

list_key = list(string_key)
list_cod = list(string_cod)
# Разделение строки посимвольно для дальнешей индексации.

index_cod = []
index_key = []

index_cod = Index(index_cod, list_cod, rotor_dict)
index_key = Index(index_key, list_key, rotor_dict)
# Инициализация поиска индесов.

sum = sum(index_key)
# Сумма ключа нужна для фиксированого ротора.

index_cod = Coder(index_key, index_cod, count,sum)
list_cod = Unindex(index_cod, list_cod, rotor_dict)
string_cod = "".join(list_cod)
print("Результат шифроки: ", string_cod)
# Блок кода отвечает за пoлный процесс шифровки кодруемого слова.

index_cod = Coder(index_key, index_cod, count,sum)
list_cod = Unindex(index_cod, list_cod, rotor_dict)
string_cod = "".join(list_cod)
print("Результат дешифровки: ", string_cod)
# Аналогичный блок когда, но отвечающий за дешифровку.

35 changes: 35 additions & 0 deletions Lab_Rab_0/Lab_Rab_0/Lab_Rab_0.pyproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>a5db5168-e575-4710-aaed-cef6c07b18d4</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>Lab_Rab_0.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<Name>Lab_Rab_0</Name>
<RootNamespace>Lab_Rab_0</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="Lab_Rab_0.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in
the BeforeBuild and AfterBuild targets below. -->
<!--<Target Name="CoreCompile" />-->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
</Project>
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# kpi-python-course
Python course repository
Kiba Evgen