יש לי פונקציה שמצפינה סטרינג שנותנים לה לפי המקום של התו הנוכחי.
public string Crypt(string text)
{
string result = "";
char[] textChars = text.ToCharArray();
for (int i = 0; i < textChars.Length; i++)
{
if (textChars[i] * i < '\uffff')
{
result += char.ConvertFromUtf32(textChars[i] * i);
}
else
{
if (char.MaxValue - textChars[i] * i + 1 >= char.MinValue)
{
result += char.ConvertFromUtf32(char.MaxValue - textChars[i] * i);
}
else
{
result += char.ConvertFromUtf32(char.MaxValue - textChars[i]);
}
}
}
return result;
}
הבעייה היא שכשנותנים לה סטרינג מידי ארוך היא נתקעת ופרטי הבעייה הם: System.ArgumentOutOfRangeException was unhandled
HResult=-2146233086
Message=ערך UTF32 חוקי הוא בין 0x000000 ל- 0x10ffff, כולל, ואינו כולל ערכי codepoint חלופיים (0x00d800 ~ 0x00dfff).
שם פרמטר: utf32
ParamName=utf32
Source=mscorlib
StackTrace:
ב- System.Char.ConvertFromUtf32(Int32 utf32)
ב- MenCrypt.MainWindow.Crypt(String text) ב- E:\מסמכים\מסמכים מענדי\Documents\2\Visual Studio 2015\Projects\MenCrypt\MenCrypt\MainWindow.xaml.cs:שורה 40
ב- MenCrypt.MainWindow.codeTxt_TextChanged(Object sender, TextChangedEventArgs e) ב- E:\מסמכים\מסמכים מענדי\Documents\2\Visual Studio 2015\Projects\MenCrypt\MenCrypt\MainWindow.xaml.cs:שורה 30
ב- System.Windows.Controls.TextChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
ב- System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
ב- System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
ב- System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
ב- System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
ב- System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
ב- System.Windows.Controls.Primitives.TextBoxBase.OnTextChanged(TextChangedEventArgs e)
ב- System.Windows.Controls.Primitives.TextBoxBase.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
ב- System.Windows.Controls.TextBox.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
ב- System.Windows.Documents.TextContainerChangedEventHandler.Invoke(Object sender, TextContainerChangedEventArgs e)
ב- System.Windows.Documents.TextContainer.EndChange(Boolean skipEvents)
ב- System.Windows.Documents.TextContainer.System.Windows.Documents.ITextContainer.EndChange(Boolean skipEvents)
ב- System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents)
ב- System.Windows.Documents.TextRange.System.Windows.Documents.ITextRange.EndChange(Boolean disableScroll, Boolean skipEvents)
ב- System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose()
ב- System.Windows.Documents.TextEditorTyping.DoTextInput(TextEditor This, String textData, Boolean isInsertKeyToggled, Boolean acceptControlCharacters)
ב- System.Windows.Documents.TextEditorTyping.TextInputItem.Do()
ב- System.Windows.Documents.TextEditorTyping.ScheduleInput(TextEditor This, InputItem item)
ב- System.Windows.Documents.TextEditorTyping.OnTextInput(Object sender, TextCompositionEventArgs e)
ב- System.Windows.Controls.Primitives.TextBoxBase.OnTextInput(TextCompositionEventArgs e)
ב- System.Windows.UIElement.OnTextInputThunk(Object sender, TextCompositionEventArgs e)
ב- System.Windows.Input.TextCompositionEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
ב- System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
ב- System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
ב- System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
ב- System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
ב- System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
ב- System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
ב- System.Windows.Input.InputManager.ProcessStagingArea()
ב- System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
ב- System.Windows.Input.TextCompositionManager.UnsafeCompleteComposition(TextComposition composition)
ב- System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
ב- System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
ב- System.Windows.Input.InputManager.ProcessStagingArea()
ב- System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
ב- System.Windows.Input.TextCompositionManager.UnsafeStartComposition(TextComposition composition)
ב- System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
ב- System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
ב- System.Windows.Input.InputManager.ProcessStagingArea()
ב- System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
ב- System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
ב- System.Windows.Interop.HwndKeyboardInputProvider.ProcessTextInputAction(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
ב- System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
ב- System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
ב- System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
ב- System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
ב- System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
ב- System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
ב- System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg, Boolean& handled)
ב- System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
ב- System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
ב- System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
ב- System.Windows.Application.RunDispatcher(Object ignore)
ב- System.Windows.Application.RunInternal(Window window)
ב- System.Windows.Application.Run(Window window)
ב- System.Windows.Application.Run()
ב- MenCrypt.App.Main() ב- E:\מסמכים\מסמכים מענדי\Documents\2\Visual Studio 2015\Projects\MenCrypt\MenCrypt\obj\Debug\App.g.cs:שורה 0
ב- System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
ב- System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
ב- Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
ב- System.Threading.ThreadHelper.ThreadStart_Context(Object state)
ב- System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
ב- System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
ב- System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
ב- System.Threading.ThreadHelper.ThreadStart()
InnerException:
מישהו יכול להסביר מה זה אומר ואיך פותרים את זה?
פורסם במקור בפורום CODE613 ב18/12/2017 11:49 (+02:00)