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
23 changes: 23 additions & 0 deletions Lab_Rab_0/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
111 changes: 111 additions & 0 deletions Lab_Rab_0/Lab_Rab_0/Lab_Rab_0/Lab_Rab_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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):
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






# (Index_cod[i] < 0 for i in range(len(Index_cod)))
#(Index_cod[i] > 36 for i in range(len(Index_cod)))
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()

l = String_cod.split()
String_cod = '_'.join(l)
l = String_key.split()
String_key = '_'.join(l)

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)

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/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>